4

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?

4
  • I've never used OptiPNG before. Is it better than Pngcrush?
    – Karan
    Jun 6, 2013 at 15:06
  • No clue. Don't know Pngcrush. Jun 8, 2013 at 13:22
  • I checked out PNGCrush, it's indeed better! Thanks! Jun 9, 2013 at 6:04
  • You're welcome! As it turns out OptiPNG is a fork of PNGCrush.
    – Karan
    Jun 9, 2013 at 14:55

1 Answer 1

1

Try the following:

@echo off
echo.
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"
9
  • 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, 2013 at 15:22
  • Much obliged!!! Jun 8, 2013 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! Jun 9, 2013 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, 2013 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... Jun 10, 2013 at 21:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .