rentzsch.com: tales from the red shed

pngcrush

Links

Reading about the Sad Story of PNG Gamma “Correction” (and it is sad) I stumbled upon pngcrush, a PNG optimizer. For kicks I downloaded it, fixed up it up so it compiled under Mac OS X (in the lamest possible way — hard-coding the gas version in the Makefile and manually #undefing in a .C file) and ran it against the 50-odd .png files in my rentzsch.com site folder.

I don’t have too many pngs, and they aren’t too large, but they still occupy 4,006,057 bytes. Running them through pngcrush dropped that to 3,507,412 bytes — a “free” savings of 498,645 bytes: 5.2% 12.5%. Not shabby. Then I got greedy. I tried the -brute option which tries “126 different methods” and the command’s own help says is “very time-consuming and generally not worthwhile.” Meh, I have a few cores to spare, let’s see what happens.

Woo, 544,823 bytes saved: 6.3% 13.6%. This is silly, but now I want to see how much further I can go. I notice the article it mentions I can use pngcrush to remove color space information altogether. PNG colorspacing has been a thorn in my side before (notice the slight color difference between the first frame of the full-length ADC Core Data vid and the second). OK, I couple -brute and -rem gAMA -rem cHRM -rem iCCP -rem sRGB. Die colorspace, die! Pure pixel data!

556,944 bytes saved, 8.5% 13.9%. Nice! But, huh, some files actually grew in size. The worst added 286 bytes. Interestingly, this file’s size didn’t budge with the previous default and -brute options. My hunch is that the file is already as “optimized” as it’s going to get, and pngcrush’s explosion and reconstruction wasn’t as good as the original creator.

Bottom-line: if you’d like a 5-8% 12-14% size savings in your .png files, sicking pngcrush on ‘em is worth the effort.

Update: I should have Googled more before posting — apparently pngcrush is outmoded. Jens Ayton writes:

Just a couple of points on the pngcrush article:

  • OptiPNG is almost always better. It also has a Mac GUI wrapper called PNGCrusher (because it used to be a pngcrush wrapper).

  • pngcrush will not create a new file that’s larger than the original unless you use -force or provide an output directory.

Update: Wow, today’s lesson is to not write blog entries at 4am. A lot of folks have written in that my percentages are, uhm, “creative”. I think I transposed the divisor in the spreadsheet and failed to notice, merrily copying the bad formula everywhere else. I updated the percentages to match your preconceived notion of “correct”.

Thursday, March 30, 2006
12:00 AM