Skip to content

Instantly share code, notes, and snippets.

@morewry
Forked from nicjansma/PngOutBatch.cmd
Created November 26, 2012 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morewry/4150401 to your computer and use it in GitHub Desktop.
Save morewry/4150401 to your computer and use it in GitHub Desktop.
Runs a PNG through PngOut multiple times at different block sizes. 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
)
REM @morewry added pngoutDir so it's aware of the location of pngout
set pngoutDir=%~d0%~p0
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
REM @morewry added pngoutDir so it's aware of the location of pngout
call !pngoutDir!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
@morewry
Copy link
Author

morewry commented Jun 18, 2013

I find this is really slow for all 24-bit PNGs in comparison to http://www.ardfry.com/pngoutwin/

@sminnee
Copy link

sminnee commented Aug 27, 2013

Do you know if there's a bash-script equivalent (or something else Linux-friendly) of this?

@morewry
Copy link
Author

morewry commented Mar 13, 2014

Not that I found at the time (tho I needed a Win version)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment