girder / django-large-image

🩻 🗺️ Django endpoints for working with large images for tile serving
Apache License 2.0
61 stars 3 forks source link

Provide error or warning for non cloud optimized formats #4

Closed banesullivan closed 2 years ago

banesullivan commented 2 years ago

If image format is not pyramidal or optimized for cloud usage, throw a warning/error because request threads will likely time out and confuse users

banesullivan commented 2 years ago

I can't think of a good way to implement this that doesn't add substantial complexity or noise around delivering the warning.

A simple check would be:

import tifftools

def has_multiple_ifds(path: str) -> bool:
    data = tifftools.read_tiff(path)
    return len(data['ifds']) > 1

if not tilesource.has_multiple_ifds(path):
    logger.warning('Tiff image does not have multiple image file directories and is likely inefficient for tile serving.')

I would recommend downstream applications add this check when doing the get_path override like so:

import tifftools
class MyViewset(..., LargeImageDetailMixin):
    def get_path(self, request, pk=None):
        ...
        data = tifftools.read_tiff(path)
        if len(data['ifds']) > 1:
            logger.warning('Tiff image does not have multiple image file directories and is likely inefficient for tile serving.')
        ...