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
Show file tree
Hide file tree
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
Preserve EXIF data in PillowImage.save_as_png
  • Loading branch information
zerolab committed Nov 25, 2023
commit e47eda2675876920eba204862c070d7dc0bea043
14 changes: 12 additions & 2 deletions tests/test_pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,24 @@ def test_save_as_png_with_icc_profile(self):
images = ["colorchecker_sRGB.jpg", "colorchecker_ECI_RGB_v2.jpg"]
for img_name in images:
with open(f"tests/images/{img_name}", "rb") as f:
image = PillowImage.open(JPEGImageFile(f))
original = PillowImage.open(JPEGImageFile(f))
icc_profile = PILImage.open(f).info.get("icc_profile")
self.assertIsNotNone(icc_profile)

saved = image.save_as_png(io.BytesIO())
saved = original.save_as_png(io.BytesIO())
saved_icc_profile = PILImage.open(saved.f).info.get("icc_profile")
self.assertEqual(saved_icc_profile, icc_profile)

def test_save_as_png_with_exif(self):
with open("tests/images/colorchecker_sRGB.jpg", "rb") as f:
original = PillowImage.open(JPEGImageFile(f))
exif = PILImage.open(f).info.get("exif")
self.assertIsNotNone(exif)

saved = original.save_as_png(io.BytesIO())
saved_exif = PILImage.open(saved.f).info.get("exif")
self.assertEqual(saved_exif, exif)

def test_save_as_gif(self):
output = io.BytesIO()
return_value = self.image.save_as_gif(output)
Expand Down
4 changes: 4 additions & 0 deletions willow/plugins/pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def save_as_png(self, f, optimize: bool = False, apply_optimizers: bool = True):
if icc_profile is not None:
kwargs["icc_profile"] = icc_profile

exif_data = self.get_exif_data()
if exif_data is not None:
kwargs["exif"] = exif_data

image.save(f, "PNG", **kwargs)
if apply_optimizers:
self.optimize(f, "png")
Expand Down