Index and display .tif, .avif and .jfif images - #415
Merged
Merged
Conversation
IMAGE_EXTENSIONS lacked .tif (the spelling scanners and Windows tools produce), .avif and .jfif, so albums of them indexed as silently empty and the serving guard 403'd them. - Add the three suffixes; require Pillow>=11.3.0, the first release whose wheels bundle AVIF. - Register the HEIF opener in media_types rather than as a side effect of importing embeddings, so is_image() implies PIL can open the file. - Serve TIFF as PNG, as HEIC already was, since only Safari renders it. Conversion runs off the event loop, handles CMYK (via the embedded ICC profile), big-endian 16-bit, 32-bit and float images without clipping, and uses fast PNG compression. - Downloads request ?original=1 so a saved TIFF/HEIC is the user's own file, not the converted display copy. Caching the conversions is tracked in #414. Fixes #364 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #364.
Problem
IMAGE_EXTENSIONScontained.tiffbut not.tif(the spelling scanners, Photoshop and Windows tools produce),.avifor.jfif. An album of.tifscans indexed as silently empty, and the serving guard 403'd those suffixes.Changes
.tif,.avifand.jfiftoIMAGE_EXTENSIONS, and update the pinned literal intest_media_types.py.Pillow>=11.3.0. I checked the wheels: 11.1.0 and 11.2.1 reportfeatures.check('avif') == False, and 11.3.0 reportsTrue. The lock is unchanged at 12.2.0.register_heif_opener()moves from an import side effect inembeddings.pyintomedia_types.py.is_image("x.heic")now implies PIL can open it even for callers that import onlymedia_types..tifthat now indexed would still be a broken image in Chrome and Firefox./images/now converts TIFF to PNG as it already did for HEIC (BROWSER_CONVERTED_EXTENSIONS). The conversion:asyncio.to_thread, so a large scan doesn't stall other requests;I;16B,IandFimages to 16-bit instead of clipping them to a blank white or black page;compress_level=1.?original=1, so a saved.tifor.heicis the user's file and not the flattened PNG. This also fixes the same existing problem for HEIC.Tests
The new
tests/backend/test_image_formats.pycovers:image/png;?original=1returns the file's exact bytes;is_image()format opens withembeddingsnever imported;Full suite: 1224 backend and 953 frontend tests pass; ruff, eslint and prettier are clean.
Review
A fresh-context adversarial review found the download regression and the deep-TIFF clipping. Both are fixed here. It also flagged:
.jfifMIME type: Python's standardmimetypestable has no.jfifentry. This is cosmetic, because<img>sniffs the bytes.🤖 Generated with Claude Code