Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
ICC profile removed from images when modified by GD #136
referenced this issue
Jun 25, 2015
changed the title from
ICC profile was removed
ICC profile removed from images when modified by GD
Jul 8, 2015
referenced this issue
Jan 27, 2016
GD library is used by NGINX module named "ngx_http_image_filter_module". This module has no configuration parameters to preserve colour profiles. I use this module and all of my images lose information about their embedded colour profile when resized. This is a serious problem because images can look too saturated or too pale depending on the device and browser.
Is it safe to say that this is a bug in the NGINX module (or perhaps PHP-GD library that it uses) and not the GD library itself? I'm asking because PHP suspended the related bug referenced above by @cmb69 and they are pointing the finger at GD. And nobody is working to get this problem fixed...
Actually, the question is how to deal with such color profiles:
(1) may not be possible for WebP, because the decoder applies the profiles (maybe this can be turned off). However, there's a big issue with (1), if the image is saved is saved in a format that does not support color profiles.
(2) defeats the purpose of color profiles, but somehow seems more appropriate for libgd.
Thank you @cmb69. The only solution that makes sense to me is to preserve colour profiles. If the information is present, then write it back when the new image is saved. If there is no information, then don't add anything.
I am not sure about GD, but ngx_http_image_filter_module doesn't change the format of images during processing. It outputs images in the same format as it receives. Even if GD can do that and the original image contains a colour profile while the output format doesn't support it, it seems there is no other choice but to leave it out.
When I create an image, I add colour profile information to it, and I expect any image processing software to respect and preserve this information. What happens now when NGINX's image filter module resizes my images, this information simply gets removed and any browser reading that resized image has no idea about its colour profile. My images look normal on regular desktops, but wide gamut displays show oversaturated colours, and some laptops show very pale colours.
I don't know much about WebP, but I see that it supports colour profiles (https://developers.google.com/speed/webp/docs/riff_container#color_profile).
If this doesn't make sense for GD library to preserve colour profile information, then I would encourage NGINX to do this in their module.
I'm just a user and know absolutely nothing at all about the workings of libgd. The product I use displays widely wrong colour in the scenario exactly like in an NGINX issue opened above by @azavisha.
I think (may be wrong, though) that there are two possible scenarios (both assume libgd is completely colour-blind, i.e. never takes note of any colour profile information, never tries to read it, keep it, write it, never does any colour space transformations using e.g. littleCMS, doesn't perform processing in a ICC-neutral profile connection space etc.).
I'm also not sure what is meant above by applying a profile and writing it back. I assume applying means performing a profile-to-profile colour space transformation and writing it back means embedding a colour profile information in a file.
Again: I have next to no idea. But from my layman's POV, my scenario 1 is much easier to implement and while not entirely correct (.e.g performing image operations in an unknown colour space is prone to all sorts of unpredictable errors and can't be consistent), at least won't remove important info from images. As is - all output is prone to entirely incorrect colour, widely depending on viewing environment. Basically, it's unpredictable to feed libgd with anything else than sRGB and even then the resulting images should be independently tagged with an sRGB profile or they will display wrong colour at times.
Sorry for the length and thanks for responding, @cmb69!
Some perhaps helpful information regarding this issue: https://stackoverflow.com/questions/5773032/how-to-stop-gd2-from-washing-away-the-colors-upon-resizing-images
@azavisha While storing the color profile during read, ignoring it during processing, but writing it back on save, would be easier to implement it seems to me there are two issues: