Keep colors consistent across OS and browsers with ImageMagick by removing profiles

Today we had a little battle with ImageMagick for our media handling product and learnt a simple trick for getting the most decent colors across different operating systems and browsers. Initially it was triggered by some images getting a nasty green “overlay” in Firefox. Some reading and verifying later it turns out FF 3.5+ does not support ICC v4 profiles — 3.0 did, they turned it off. Now, in general embedded color profiles is a little nightmare because of the very different ways they works in browsers.

The solution we ended on — that seems to work quite well in all OS+browser combinations — was to extract the color profile from the original image, then convert the image to use the ICC v2 black scaled profile (available here at ICC’s site) and finally strip all color profiles from the image. The end result of this is the following two commands. Notice that you probably want to check that profile.icc is bigger than 0 bytes not that it matters to ImageMagick.

convert image.jpg profile.icc
convert image.jpg -profile profile.icc -profile /path/to/sRGB_IEC61966-2-1_black_scaled.icc -strip working-image.jpg

So far this seems to be working good, but leave a comment if you have suggestions to improve it or a better solution.