Skip to content

Instantly share code, notes, and snippets.

@nicjansma
Created May 16, 2012 01:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nicjansma/2706660 to your computer and use it in GitHub Desktop.
Save nicjansma/2706660 to your computer and use it in GitHub Desktop.
Runs a PNG through PngOut multiple times at different block sizes. Shows the file-size savings during and at the end. More details @ http://nicj.net/2012/05/15/pngoutbatch
@echo off
setlocal enabledelayedexpansion
REM
REM PngOutBatch
REM
REM Nic Jansma - nic@nicj.net
REM
REM Runs a PNG through PngOut multiple times at different block sizes. Shows the
REM file-size savings during and at the end.
REM
REM More details: http://nicj.net/2012/05/15/pngoutbatch
REM
REM Usage: PngOutBatch.cmd [image.png] [number of passes per block size - default 5]
REM
if {%1}=={} (
call :Usage
exit /b 1
)
set filePath=%1
set numberOfPasses=5
if NOT {%2}=={} (
set numberOfPasses=%2
)
REM
REM Save original file size
REM
call :FileSize !filePath!
set origFileSize=!fileSize!
set currentFileSize=!origFileSize!
REM
REM Run PngOut in a loop
REM
for %%b in (0 128 192 256 512 1024 2048 4096 8192) do (
set blockSize=%%b
echo Blocksize: !blockSize!
for /l %%n in (1,1,!numberOfPasses!) do (
set passNumber=%%n
call pngout /b!blockSize! /r !filePath! > nul
REM check file size after this iteration
call :FileSize !filePath!
set thisFileSize=!fileSize!
set /a savings = currentFileSize - thisFileSize
if !savings! GTR 0 (
echo Iteration #!passNumber!: Saved !savings! bytes
) else (
echo Iteration #!passNumber!: No savings
)
set currentFileSize=!thisFileSize!
)
)
REM
REM Check final file size
REM
call :FileSize !filePath!
set finalFileSize=!fileSize!
set /a savings = origFileSize - finalFileSize
if !savings! GTR 0 (
echo !filePath!: SUCCESS: !origFileSize! bytes originally, !finalFileSize! bytes final: !savings! bytes saved
) else (
echo !filePath!: No change
)
endlocal
exit /b 0
REM
REM Helper functions
REM
:FileSize
set fileSize=%~z1
goto :eof
:Usage
echo PngOutBatch.cmd [filename] [number of passes, defaults to 5]
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment