diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-05-25 22:50:24 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-05-25 22:50:24 +0200 |
commit | 7304857570feecfc7d3d23bc26e6d1c1c3de90ab (patch) | |
tree | e05042f3989733cb77b63951c4fce979174654a0 | |
parent | a7e832b63a214f71d9db9d17d20cb2aff46a948e (diff) |
Fix thumbnail and JPEG orientation for odd CR2 files
-rwxr-xr-x | bin/pyggle | 34 |
1 files changed, 33 insertions, 1 deletions
@@ -38,6 +38,35 @@ def rotate_image(image, exif_tag): return image +def rotate_preview(filename, exif_tag): + if "Image Orientation" not in exif_tag: + return + + orientation = exif_tag["Image Orientation"].values + rotation = None + + if 3 in orientation: + rotation = "-1" + if 6 in orientation: + rotation = "-9" + if 8 in orientation: + rotation = "-2" + + if not rotation: + return + + subprocess.run( + [ + "exiftran", + "-i", + rotation, + filename, + ], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + + def format_f(value, precision=1): if value % 1 == 0: return f"{value:.0f}" @@ -290,7 +319,9 @@ class Thumbnail: if not self.thumbname.lower().endswith((".jpeg", ".jpg")): self.thumbname += ".jpg" - im = rotate_image(im, self.exif_tag) + if not filename.lower().endswith((".cr2", ".cr3", ".rw2")): + im = rotate_image(im, self.exif_tag) + im.thumbnail((self.size * 4, self.size * 2)) im = im.convert("RGB") im.save(self.thumbname, "JPEG") @@ -322,6 +353,7 @@ class Thumbnail: ] ) self.jpegname = jpegname + rotate_preview(jpegname, self.exif_tag) except FileNotFoundError: pass |