Tools like PNGOUT blithely strip out color profiles (the iCCP chunk), which arguably makes the tools lossy because it changes the appearance of non-sRGB images in nearly all modern browsers.

I've found a solution. Gimp will offer to autoconvert to sRGB when opening an affected image. Saving and using PNGOUT is then perfectly fine. The original and Gimp-assisted recompressed images will give identical screenshots from a browser to the extent that every pixel will have the same RGB value with both image files. This is exactly what I want.

However, I'm dealing with hundreds of images and opening them in Gimp this way and then saving them is not an automated process. How can I automatically properly convert PNGs to the sRGB color profile prior to recompressing them?

Note: I've tried ImageMagick's convert with various sRGB.icc profiles, but every time I've tried it's a bit lossy (like giving #cccdcc instead of #cccccc) and thus ruins the ability to use PNG's greyscale storage for grey images, both of which are undesired.

2 Answers
2

I'd used the ICC profiles available on the ICC's website, which was strangely enough a mistake, since they introduce the errors I mentioned in the question.

GraphicsMagick (slightly lossy)

GraphicsMagick does this in a very slightly lossy method (brighter colors are reduced by one, like from #cccccc to #cbcbcb). However, this doesn't ruin greys and allows for better recompression.

Since this is likely the easier method to apply if strict perfection isn't needed, I've included it. Get a proper sRGB ICC profile, like the one in the assorted profiles pack offered by Little CMS or the one included with Ghostscript, and run the following:

gm convert in.png -profile /path/to/srgb.icc -strip out.png

Gimp automation (non-lossy)

After I found that GraphicsMagick was inexact, I worked out a Script-Fu script which uses Gimp's exact method. To prepare to use it, save the following contents to ~/.gimp-2.8/scripts/png-to-srgb.scm

This is a good alternative, so I've upvoted it. One effect of it that got me when I tried it was that the color profiles were about a kilobyte each, so on the smaller files that are a few hundred bytes when the color profiles are removed, this method will increase their size considerably.
–
OlatheFeb 25 '13 at 19:51