thumbnail: Generate a transcoded high-res version of HEIC/TIFF images.

If the content-type of the image is not in INLINE_MIME_TYPES, then we
do not expect browsers to be able to display it.  This behaviour is
particularly confusing because the thumbnail will render properly,
since that will be in the more widely-supported WebP format, but the
lightbox will show a broken image.

In these cases, generate a high-resolution (4032x3024) "thumbnail"
which clients can choose to use instead.  This thumbnail format is not
in the listed in the server's advertised thumbnail size list, because
it is not reliably generated for every image.

The transcoded thumbnail format is set on the `img` tag if it is
generated, and the original content-type is always passed to the
client, so it can decide how or if to render the original image.  This
content-type is as the _original uploader_ specified it, so may be
incorrect.

The transcoded image is not animated, even if the original was.  HEIC
files can nominally be animated, but in testing libvips was not able
to correctly recognize them as such.  TIFF files are parsed as being
"animated," with one page per frame; this is of dubious utility, so
we merely transcode the first page.  Always generating a static
transcoded image serves to also limit the computational time spent.

THUMBNAIL_OUTPUT_FORMATS is switched to be a tuple to ensure that it
is not accidentally mutated.
This commit is contained in:
Alex Vandiver
2024-12-20 20:18:34 +00:00
committed by Tim Abbott
parent 9fa5ab951c
commit 230bae17bb
10 changed files with 334 additions and 58 deletions

View File

@@ -669,6 +669,11 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
"data-original-dimensions",
f"{metadata.original_width_px}x{metadata.original_height_px}",
)
if metadata.original_content_type:
img.set(
"data-original-content-type",
metadata.original_content_type,
)
else:
img.set("src", image_url)