OptiPNG: Optimize all your PNGs recursively with only a single command

OptiPNG is an open-source PNG optimizer that recompresses image files to a smaller size in order to increase your overall website and page speed.

Many website managers and graphic designers compress their image files with online converters such as TinyPNG or compressJPG to make it faster and to save bandwith. Certainly, this is not always the most efficient method since you still need to reupload all compressed images to your CMS to re-implement them. If you have a lot of images on your website, this process can become very time consuming.

OptiPNG converts many external formats to optimized PNGs with only a single command and is super useful if you use just one directory for your website assets.

However, if you need to parse a whole structure of different directories and subdirectories, we prepared the following code for you that will be enable you to recursively optimize your files:

SET "sourcedir=C:\www.example.com\"
FOR /r "%sourcedir%" %%a IN (*.png) DO (
C:\Users\exampleadmin\Desktop\optipng.exe "%%a")

Simply add this code to a batch file (.bat), replace the placeholders (example.com) and run the command.  OptiPNG will overwrite all existing files in all directories.

You can safe a lot of time by recursively optimizing your image files. Do another page speed test and check the results.


Last but not least remember: Saving precious bandwith also helps to save the planet 😉

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.