Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds TIFF Renderer to Boss Tiles #119

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions django/bosstiles/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,18 @@ def render(self, data, media_type=None, renderer_context=None):
file_obj.seek(0)
return file_obj.read()

class TIFFRenderer(renderers.BaseRenderer):
""" A DRF renderer for rendering an image as a TIFF file """
media_type = 'image/tiff'
format = 'tiff'
charset = None
render_style = 'binary'

@check_for_403
@check_for_429
def render(self, data, media_type=None, renderer_context=None):
file_obj = io.BytesIO()
# Save the image data as TIFF instead of JPEG
data.save(file_obj, "TIFF")
file_obj.seek(0)
return file_obj.read()
6 changes: 3 additions & 3 deletions django/bosstiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import bossutils

from .renderers import PNGRenderer, JPEGRenderer
from .renderers import PNGRenderer, JPEGRenderer, TIFFRenderer


class CutoutTile(APIView):
Expand All @@ -36,7 +36,7 @@ class CutoutTile(APIView):

* Requires authentication.
"""
renderer_classes = (PNGRenderer, JPEGRenderer)
renderer_classes = (PNGRenderer, JPEGRenderer, TIFFRenderer)

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -175,7 +175,7 @@ class Tile(APIView):

* Requires authentication.
"""
renderer_classes = (PNGRenderer, JPEGRenderer)
renderer_classes = (PNGRenderer, JPEGRenderer, TIFFRenderer)

def __init__(self):
super().__init__()
Expand Down