How to batch compress images using OptiPNG

optipng-compress1

OptiPNG is a powerful command line tool that compresses PNG images through optimisation.

With it you can process a collection of PNG images to dramatically reduce their size, which is particually helpful for websites.

The command line below can be used with OptiPng to process every PNG file in a the same folder, it requires the OptiPNG Windows build to be in the same folder, which you can download from here: http://optipng.sourceforge.net/

Simply save the command below into a dos batch file, along with your PNG images to compress and run.

The process can take anywhere from seconds to minutes to PNG, depending on how large and complicated it is.

@echo off

ECHO Set working directory
pushd '%~dp0'

ECHO - For all PNG images in folder '%~dp0'
for /f "usebackq eol=; tokens=1 delims=," %%f in ('%~dp0*.png') do (

ECHO - run optipmg on found PNG image %%~nxf
"%~dp0optipng" -nc -nb -o7 -full "%~dp0%%~nxf"

)

Need help, download the example ZIP file below:

www.itsupportguides.com/downloads/optipng-example.zip