wagtail / Willow

A wrapper that combines the functionality of multiple Python image libraries into one API
https://willow.wagtail.org/
BSD 3-Clause "New" or "Revised" License
273 stars 53 forks source link

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

Closed andre-fuchs closed 9 months ago

andre-fuchs commented 10 months ago

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

zerolab commented 10 months ago

@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 commented 10 months ago

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 commented 10 months ago

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

Stormheg commented 10 months ago

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

Two birds with one stone!

andre-fuchs commented 9 months ago

Thanks @zerolab for tidying up!

zerolab commented 9 months ago

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

andre-fuchs commented 9 months ago

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 commented 9 months ago

@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.