Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using OptiPNG for a large amount of PNGs I need to optimize. I can get it to run with a batch script where the application and image are in one folder together.

start.bat contains:

start _OPNG.exe *.png -zc9 -zm9 -zs3 -f0-5 -nc -strip "all"

However, let's say I have a folder in d:\images with 1.png through 10.png, then I've got a sub-folder d:\images\sub1 with 1sub.png through 10sub.png.

The app is located in, let's say, f:\OptiPNG\optipng.exe.

I want a batch file where I have to manually edit just the location of the image folder I want to optimize. The batch file should take into account all PNGs in that folder and its subfolders.

Anybody able to help me out?

share|improve this question
I've never used OptiPNG before. Is it better than Pngcrush? – Karan Jun 6 '13 at 15:06
No clue. Don't know Pngcrush. – Grumpy ol' bear Jun 8 '13 at 13:22
I checked out PNGCrush, it's indeed better! Thanks! – Grumpy ol' bear Jun 9 '13 at 6:04
You're welcome! As it turns out OptiPNG is a fork of PNGCrush. – Karan Jun 9 '13 at 14:55
up vote 1 down vote accepted

Try the following:

@echo off
set apppath="F:\OptiPNG\OptiPNG.exe"
if [%1]==[] echo Usage: %0 "PNG Dir" && echo. && echo Error: Invalid parameters && goto :EOF
if not exist %1 echo Usage: %0 "PNG Dir" && echo. && echo Error: Invalid directory "%~1" && goto :EOF
%apppath% "%~1\*.png" -zc9 -zm9 -zs3 -f0-5 -nc -strip "all"
for /d /r "%~1" %%a in (*.*) do %apppath% "%%~a\*.png" -zc9 -zm9 -zs3 -f0-5 -nc -strip "all"
share|improve this answer
Just in case it's not clear, save it as something like Optimise.bat, then call with Optimise "D:\Images" to optimise all PNGs in the specified dir and all its sub-dirs. – Karan Jun 6 '13 at 15:22
Much obliged!!! – Grumpy ol' bear Jun 8 '13 at 13:21
If I could bother you again, Karan. Could you do another batch file, but this time with Pngcrush as application? Don't worry much about the -xyz commands, these I'll look up myself in Pngcrus and add accordingly to the batch file! Thanks! – Grumpy ol' bear Jun 9 '13 at 6:05
I'm not on my PC right now so can't confirm, but IIRC pngcrush should accept wildcards like *.png just as optipng does. In that case all you need to do is modify apppath to point to pngcrush.exe, and of course ensure you're using parameters appropriate to the program. – Karan Jun 9 '13 at 14:54
I tried, it doesn't work. PNGCrush has different commands that I apparently am too dumb to incorporate. I can read the "usage" section when executing pngcrush.exe but that's...really...descriptive... – Grumpy ol' bear Jun 10 '13 at 21:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.