Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix color management by keeping ICC color profiles and EXIF data in addition #136

Merged
merged 15 commits into from
Nov 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Modify the implementation of auto_orient() so that it uses the corres…
…ponding PIL.ImageOps operation
  • Loading branch information
andre-fuchs committed Nov 2, 2023
commit a39e211693ef6d139089262a7d78639970efe6bd
35 changes: 2 additions & 33 deletions willow/plugins/pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
except ImportError:
pass

from PIL import ImageOps
from willow.image import (
AvifImageFile,
BadImageOperationError,
Expand Down Expand Up @@ -351,39 +352,7 @@ def save_as_avif(self, f, quality=80, lossless=False, apply_optimizers=True):
def auto_orient(self):
# JPEG files can be orientated using an EXIF tag.
# Make sure this orientation is applied to the data
image = self.image

if hasattr(image, "_getexif"):
try:
exif = image._getexif()
except Exception: # noqa: BLE001
# Blanket cover all the ways _getexif can fail in.
exif = None
if exif is not None:
# 0x0112 = Orientation
orientation = exif.get(0x0112, 1)

if 1 <= orientation <= 8:
Image = _PIL_Image()
ORIENTATION_TO_TRANSPOSE = {
1: (),
2: (Image.Transpose.FLIP_LEFT_RIGHT,),
3: (Image.Transpose.ROTATE_180,),
4: (
Image.Transpose.ROTATE_180,
Image.Transpose.FLIP_LEFT_RIGHT,
),
5: (
Image.Transpose.ROTATE_270,
Image.Transpose.FLIP_LEFT_RIGHT,
),
6: (Image.Transpose.ROTATE_270,),
7: (Image.Transpose.ROTATE_90, Image.Transpose.FLIP_LEFT_RIGHT),
8: (Image.Transpose.ROTATE_90,),
}

for transpose in ORIENTATION_TO_TRANSPOSE[orientation]:
image = image.transpose(transpose)
image = ImageOps.exif_transpose(self.image)
andre-fuchs marked this conversation as resolved.
Show resolved Hide resolved

return PillowImage(image)

Expand Down