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
Images lose their icc_profile #366
Comments
Presumably the icc profile is dropped to reduce file size. Even if it wasn't dropped, mobile browsers tend to ignore colour profiles in the interests of performance, meaning the colours are still muted. A good solution is to convert the colour profile of the image to sRGB (which is aimed at consumer screens) before the profile is dropped. We have some code that will do this at https://github.com/ixc/icekit-imagetools/blob/develop/imagetools/utils/srgb.py Question for @SmileyChris : should converting to sRGB before dropping the profile be the default easy-thumbnails behaviour? |
probably related: #397 |
I have made an image processor that converts an image to sRGB colour profile and RGB colour space so that there is the minimum of visual disruption when the colour profile is dropped. Add it to the beginning of THUMBNAIL_PROCESSORS as per https://easy-thumbnails.readthedocs.io/en/latest/ref/processors/#custom-processors. https://gist.github.com/cogat/fbdfeb099564ef0cdda8491b0d65557c I think this can replace the default |
@cogat thanks for that solution. It works for me! However, I would like to keep the ICC profile embedded instead of applying it. Any suggestions on how to go regarding that? Thanks! |
If you want to keep the profile embedded, be aware that mobile browsers (at least last time I checked, a few years ago) discard the profile and so will render uncorrected (dull) colours. I'm guessing there is a processor in easythumbnails - or an action of PIL, that discards the ICC profile (see the two contrasting cases up top). I think that processor needs to be skipped or reimplemented in order to prevent the profile discarding. |
First place to check/bypass would be https://github.com/SmileyChris/easy-thumbnails/blob/master/easy_thumbnails/processors.py#L38 which ensures an RGB colour space. NB colour space (RGB/CMYK) is a different concept to ICC profile. |
Hi @cogat, I investigated, and it's not a processor in easythumbnails that discards the ICC profile. It's saving the image in At this line: I debugged, and at that point, As soon as we exit from Got any suggestions? |
Hey @siovene unfortunately I don't have a thumbnails project warmed up to look at or test with, but https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#jpeg seems to say if you could pass the
However, at this point you might be re-implementing or overriding so much that it is easier to create your own thumbnail script? |
I think I'll go with a fork and sending a pull request. I'm involved too deeply in easy-thumbnailer to replace it. Thanks! |
It's been a while since I used this project, but I seem to remember that pillow doesn't maintain any metadata once you start transforming images. You need to extract extract metadata like ICC, do any image transforms, then when saving it with pillow, pass the ICC metadata into the save method. Keep in mind that this project is a thumbnailer, the point is to have Small (file size) image output. ICC, exif metadata can actually be quite large - sometimes larger than the thumbnail itself! Note that depending on the ICC profile, you may be able to replace it with a much smaller substitute without visible degradation. |
Hi @jaddison, true, regarding file size. However, in my case, I need thumbnails to be as color correct as possible. I'm implementing this so that there would be settings to specify which thumbnail aliases should keep the ICC profile, and which should discard them. For my small thumbnails, I would discard the ICC and apply it in the sRGB space. For the large thumbnails I would keep it. I use the word thumbnail very loosely because in my project some of them are quite large. |
Can anyone have a look at my PR? I understand if it takes longer to get merged, but if I could get a summary opinion I could use it in my fork while I wait for the merge. I'm forked from 2.6 anyway because I'm on Django 1.11. |
Loses icc_profile and looks less vibrant
Does not lose icc_profile
See http://stackoverflow.com/questions/13672777/python-pil-changing-colour-profile-to-untagged-rgb-on-crop-scale-and-save
using version 2.2
The text was updated successfully, but these errors were encountered: