mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 01:47:41 +00:00
thumbnail: Store the post-orientation-transformation dimensions.
Modern browsers respect the EXIF orientation information of images, applying rotation and/or mirroring as specified in those tags. The the `width="..."` and `height="..."` tags are to size the image _after_ applying those orientation transformations. The `.width` and `.height` properties of libvips' images are _before_ any transformations are applied. Since we intend to use these to hint to rendering clients the size that the image should be _rendered at_, change to storing (and providing to clients) the dimensions of the rendered image, not the stored bytes.
This commit is contained in:
committed by
Tim Abbott
parent
e7ac62aad7
commit
e4a8304f57
@@ -295,11 +295,23 @@ def maybe_thumbnail(attachment: AbstractAttachment, content: bytes) -> ImageAtta
|
||||
try:
|
||||
# This only attempts to read the header, not the full image content
|
||||
with libvips_check_image(content) as image:
|
||||
# "original_width_px" and "original_height_px" here are
|
||||
# _as rendered_, after applying the orientation
|
||||
# information which the image may contain.
|
||||
if (
|
||||
"orientation" in image.get_fields()
|
||||
and image.get("orientation") >= 5
|
||||
and image.get("orientation") <= 8
|
||||
):
|
||||
(width, height) = (image.height, image.width)
|
||||
else:
|
||||
(width, height) = (image.width, image.height)
|
||||
|
||||
image_row = ImageAttachment.objects.create(
|
||||
realm_id=attachment.realm_id,
|
||||
path_id=attachment.path_id,
|
||||
original_width_px=image.width,
|
||||
original_height_px=image.height,
|
||||
original_width_px=width,
|
||||
original_height_px=height,
|
||||
frames=image.get_n_pages(),
|
||||
thumbnail_metadata=[],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user