Batch PNGOut File Compressor

Thu Jul 07 2011Uncategorized

This is a batch file I wrote to handle the compression directories full of PNG files using Ken Silverman’s amazing PNGOUT tool.

Bear in mind that this isn’t exactly a replacement for PNGOUTWin which supports asynchronous file compression taking advantage of multiple cores, this is merely a batch file that recursively navigates through a given directory and throws all PNGs one at a time at PNGOUT.

Output example:

Output for D:\Images\ for 88 files 1252 kb before 922 kb after saving a total of 330 kb (26%) Press any key to continue . . .

Instructions:

  1. Download Ken Silverman’s command line PNGOUT tool (as provided in the link)

  2. Set the path for the pngo variable in the batch file

  3. Run the batch file simply like so

  • pngout-batch “D:\Images\”
  1. Optional: Create a shortcut to the batch file and place it in your SendTo folder for your user account for the sake of convenience
  • Windows XP

  • C:\Documents and Settings\\SendTo

  • Windows Vista / 7

  • C:\Users\\AppData\Roaming\Microsoft\Windows\SendTo

Here is a preview of the batch file or you can download the batch file itself at the bottom of the post.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: PNGOut Compressor Batch File v1.0 :: :: Author: Terry J. Butler :: Website: / :: Post URI: /2011/07/07/batch-pngout-file-compressor/ :::READ ME:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Distribute this batch file as you'd like but I ask that you please leave this :: commented header section intact. :: If you want to modify this batch file, I ask that you give credit where credit :: is due. :: :: Thanks to Ken Silverman for the fantastic PNGOut. Nothing compares to it. :: You'll need to download it from http://advsys.net/ken/utils.htm, place it
:: somewhere convenient and change the path to it for the 'pngo' variable under the :: "CONFIGURATION" header :: :: Thanks to the NT reference at SS64.com (http://ss64.com/nt/) for an incredible :: wealth of information that helped shape this batch file :: :: Head to the link in the Post URI above for further details on how to use. :::CHANGE LOG::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: :: v1.0 :: - Initial Release :: :::CONFIGURATION:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Set this path to the locaation of your pngout.exe file SET pngo="D:\tools\pngout.exe" ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@echo off

:: Setting EnabledDelayedExpansion will cause each variable to be expanded at execution :: time rather than at parse time. EnableDelayedExpansion is Disabled by default. setLocal EnableDelayedExpansion

:: set some arithmetic capable variables set /a value=0 set /a sum=0 set /a sumOriginal=0 set /a count=0 set /a diff=0 set /a diffPercent=0

pushd %1

FOR /R %%G IN (\*.png) DO (
	echo Now Compressing %%G 
	
	set /a value=%%~zG
	set /a sum=!sum!+!value!	
	set /a count+=1
	%pngo% "%%G"
)

set /a sumOriginal=sum/1024

set /a value=0
set /a sum=0

FOR /R %%G IN (\*.png) DO (
	set /a value=%%~zG
	set /a sum=!sum!+!value!	
)

set /a sum=sum/1024	
set /a diff=!sumOriginal!-!sum!	
set /a diffPercent=(100\*(!sumOriginal!-!sum!))/!sumOriginal!;	

@echo Output for %CD% for %count% files
@echo !sumOriginal! kb before
@echo !sum! kb after	

@echo saving a total of !diff! kb (!diffPercent!%% decrease)

popd

:: Unset variables SET _value= SET _sum= SET _sumOriginal= SET _count= SET _diff= SET _diffPercent=

pause

Download pngout-batch.bat

GatsbyNetlifyReactTypeScriptTailwind CSS
© Copyright 2008-2022 Terry Butler