Philipp Hörist pushed to branch master at gajim / gajim
Commits:
b45b6f95 by mesonium at 2025-10-19T16:13:36+02:00
fix: Rotate image preview correctly
- - - - -
39b7725f by mesonium at 2025-10-19T16:13:51+02:00
fix: Apply scaling to image previews again
- - - - -
3 changed files:
- gajim/common/multiprocess/thumbnail.py
- gajim/common/util/image.py
- gajim/gtk/preview/image.py
Changes:
=====================================
gajim/common/multiprocess/thumbnail.py
=====================================
@@ -15,6 +15,8 @@
from PIL import Image
from PIL import ImageFile
+from gajim.common.util.image import get_image_orientation
+
ImageFile.LOAD_TRUNCATED_IMAGES = True
@@ -58,6 +60,10 @@ def _create_thumbnail_with_pil(data: bytes, size: int) ->
tuple[bytes, dict[str,
input_file.close()
raise
+ image_orientation = get_image_orientation(image)
+ if image_orientation != 0:
+ image = image.rotate(image_orientation, expand=True)
+
image_width, image_height = image.size
n_frames = getattr(image, "n_frames", 1)
if size > image_width and size > image_height and n_frames == 1:
=====================================
gajim/common/util/image.py
=====================================
@@ -126,6 +126,20 @@ def scale_with_ratio(size: int, width: int, height: int)
-> tuple[int, int]:
return size, int(size / ratio)
+def get_image_orientation(image: Image.Image) -> int:
+ exif = image.getexif()
+ exif_orientation_code = 274
+ orientation = exif.get(exif_orientation_code, 1)
+ degrees = {
+ 1: 0,
+ 3: 180,
+ 6: 270,
+ 8: 90
+ }.get(orientation, 0)
+
+ return degrees
+
+
def resize_gif(
image: ImageFile.ImageFile, output_file: BytesIO, resize_to: tuple[int,
int]
) -> None:
=====================================
gajim/gtk/preview/image.py
=====================================
@@ -122,7 +122,7 @@ def _create_image_thumbnail(self) -> None:
create_thumbnail,
self._orig_path,
self._thumb_path,
- app.settings.get("preview_size"),
+ app.settings.get("preview_size") *
app.window.get_scale_factor(),
self._mime_type,
)
future.add_done_callback(
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/ffc288a0df8919bd5848f6431451bd1e5a4dfe73...39b7725fb4d667a335a51ae91b20394037420275
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/ffc288a0df8919bd5848f6431451bd1e5a4dfe73...39b7725fb4d667a335a51ae91b20394037420275
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]