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

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

merged 15 commits into from
Nov 26, 2023

Conversation

andre-fuchs
Copy link
Contributor

@andre-fuchs andre-fuchs commented Nov 2, 2023

Adds methods to keep the ICC color profile and EXIF data if supported for JPEG, PNG, WebP and AVIF file formats. Extends the unit tests accordingly. All tests passed.

Closes #114
Closes #137

…from the original image. Add first tests for these methods using a photo of a color checker with two different ICC profiles. Image source of the sRGB version: https://en.wikipedia.org/wiki/ColorChecker#/media/File:Gretag-Macbeth_ColorChecker.jpg
…data(). Add sanity check to save_as_jpeg() method for testing purposes
…data(). Add sanity check to save_as_jpeg() method for testing purposes
…data(). Add sanity check to save_as_jpeg() method for testing purposes
@zerolab
Copy link
Collaborator

zerolab commented Nov 2, 2023

@andre-fuchs thank you very much for this.

We use pre-commit with black/ruff, and is one of the testing dependencies - https://github.com/wagtail/Willow/blob/main/pyproject.toml#L44

Can you run pre-commit install then pre-commit run --all-files to lint?

@andre-fuchs
Copy link
Contributor Author

andre-fuchs commented Nov 2, 2023

Thanks @zerolab. Just did learn about pre-commit and reformatted the code.

Here is a quick summary of this update:

I added two methods to the class PillowImage() to add the ICC color profile and the EXIF data. These are applied in the methods save_as_jpeg(), save_as_png(), save_as_webp() and save_as_avif(). New unit tests were added to test this implementation with two image files with different ICC profiles.

This was strongly inspired by #63, which also modified the auto_orient() method. I think this was necessary to fix a bug caused by the Orientation EXIF tag. Not totally sure, though. Please double check if this is necessary.

Note: This workaround is not necessary anymore.

@zerolab
Copy link
Collaborator

zerolab commented Nov 6, 2023

Thank you @andre-fuchs. Will aim to review and test ASAP

@Stormheg
Copy link
Member

The changes to auto_orient will also end up fixing #137.

Two birds with one stone!

Copy link
Member

@Stormheg Stormheg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

@zerolab zerolab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andre-fuchs sorry for the delay. Lots of fantastic work here! Added a few notes on improving the API a bit.

Do let me know if you have the capacity to address these

willow/plugins/pillow.py Outdated Show resolved Hide resolved
willow/plugins/pillow.py Outdated Show resolved Hide resolved
willow/plugins/pillow.py Show resolved Hide resolved
…to the save methods of the WandImage class as well. ICC color profiles do work with JPEG and WebP. EXIF data does work with JPEG only. Add unit tests.
willow/plugins/wand.py Outdated Show resolved Hide resolved
@zerolab zerolab merged commit 3f759f2 into wagtail:main Nov 26, 2023
7 checks passed
zerolab pushed a commit that referenced this pull request Nov 26, 2023
…ddition (#136)

* Add ICC profile and EXIF data methods to the PillowImage class
   Includes tests for these methods using a photo of a color checker with two different ICC profiles. Image source of the sRGB version: https://en.wikipedia.org/wiki/ColorChecker#/media/File:Gretag-Macbeth_ColorChecker.jpg
* Modify the implementation of auto_orient() so that it uses the corresponding PIL.ImageOps operation
* Add tests for save_as_ and auto_orient methods.
* Add ICC profile and EXIF data methods to WandImage class as well. ICC color profiles do work with JPEG and WebP. EXIF data does work with JPEG only. Add unit tests.

* Preserve EXIF data in PillowImage.save_as_png and WandImage.save_as_png

Co-Authored-By: Ștefan Istrate <[email protected]>
@andre-fuchs andre-fuchs deleted the fix-color-management branch November 27, 2023 11:27
@andre-fuchs
Copy link
Contributor Author

Thanks @zerolab for tidying up!

@zerolab
Copy link
Collaborator

zerolab commented Nov 27, 2023

Thank you for helping us take this over the finish line, @andre-fuchs!
It has been way too long coming

@andre-fuchs
Copy link
Contributor Author

andre-fuchs commented Nov 27, 2023

Cannot wait to use it. Many of my clients were complaining about the color conversion in Wagtail. This should solve it.

Upgrading Wagtail via PIP doesn’t do the trick yet:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. wagtail 5.2.1 requires Willow[heif]<1.7,>=1.6.2, but you have willow 1.7.0 which is incompatible.

@laymonage
Copy link
Member

laymonage commented Nov 27, 2023

@andre-fuchs You can install version 1.6.3 instead: https://github.com/wagtail/Willow/releases/tag/v1.6.3. Wagtail's upper version boundary on Willow likely won't be updated until Wagtail 6.0 unless wagtail/wagtail#11272 is backported to the stable/5.2.x branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants