Long execution time and high CPU load
Advanced PNG optimization program
Status: Beta
Brought to you by:
cosmin
Hello,
I have a website with thousands of PNG images (50k+).
I run a cron job every night to optimize the PNG images for Google PageSpeed.
The last execution started at midnight, it is now 17:00 and optipng is still running and using most of the CPU of my dedicated server.
I have noticed that optipng will spend hours trying to optimize images that were already optimized during the last execution
Thank you
Help?
Unfortunately, it is not possible to detect the "already-optimized" status of a PNG image, in the way that you can, e.g., with a JPEG image.
When you're optimizing baseline JPEG, you just check if the Huffman trees are the optimized or not. And if you see that they're optimized, you're done. But with PNG, there's no such thing. Most (virtually all) of the PNG images already have their Huffman trees in optimized form, inside the zlib datastream, and yet, PNG optimization is much more than that. There is no way to tell if a PNG image has already been through a prior optimization phase repeated compression trials, etc., unless someone would set an "optimized" indicator in a custom chunk (which, oddly enough, would take a little extra space for itself).
There is an alternative that works if you already know how large an optimized IDAT should be. (That is, if you have intimate knowledge of the statistics of your images, and that's usually a big if...) I'm sorry that OptiPNG cannot help you with that; but pngcrush can. (See the option -already in the pngcrush manual.)
If you want to skip the images that have been recently processed (either optimized, or saved by some external tool -- you wouldn't be able to distinguish that in general, so it's up to you to know the age of your files), you can do that by checking the time stamp. But for that, you'd have to write a script wrapper (in Shell, or in Python, etc.), because this kind of file selection is outside of the scope of OptiPNG. For example, if you're using Unix, you can use the "find" command with options like "-exec" and "-newer".