I'm using PNGOUT for months in my png optimization batch, and I want pngout can output other exit code(e.g.: 1) if file is not optimized successfully, letting exit code 0 for file is optimized successfully. So that I can control optimization flow more completely. Thanks.
Best regards, Roy
counting_pine at
Re: pngout with exit code
If it's any help, Windows NT and later have a console that supports (relatively) advanced batch scripting features, such as CALLing labels and IF comparisons, and it's possible to test the file size from within a batch file to see whether it's changed. Here's a reasonsbly simple example:
@echo off pngout /y %1 temp.png
call :checksize %1 temp.png goto :eof
:checksize if %~z2 lss %~z1 ( echo File was shrunk from %~z1 bytes to %~z2 bytes :^) ) else ( echo File was not shrunk :( )
goto :eof
Awesoken at
Thanks for posting a solution, Counting Pine. I wanted to add that PNGOUT does return a 1 in some instances, but only for errors like "file not found".
roytam1 at
counting_pine said at
If it's any help, Windows NT and later have a console that supports (relatively) advanced batch scripting features, such as CALLing labels and IF comparisons, and it's possible to test the file size from within a batch file to see whether it's changed. Here's a reasonsbly simple example:
@echo off pngout /y %1 temp.png
call :checksize %1 temp.png goto :eof
:checksize if %~z2 lss %~z1 ( echo File was shrunk from %~z1 bytes to %~z2 bytes :^) ) else ( echo File was not shrunk :( )
goto :eof
but I'm using pngout on my win98 box. :-\
counting_pine at
roytam1 said at
but I'm using pngout on my win98 box.
Bummer... OK, you might like this method better:
@echo off pngout /y %1 temp.png | %windir%\command\find.exe "Chg:" if not errorlevel 1 echo file was shrunk
I qualified the file path for find.exe, because I already have another program called find.exe in my %PATH%.
roytam1 at
counting_pine said at
roytam1 said at
but I'm using pngout on my win98 box.
Bummer... OK, you might like this method better:
@echo off pngout /y %1 temp.png | %windir%\command\find.exe "Chg:" if not errorlevel 1 echo file was shrunk
I qualified the file path for find.exe, because I already have another program called find.exe in my %PATH%.
using pipe will remove interactive progress and make it "look like" freeze/hang. I want interactive progress.
Awesoken said at
Thanks for posting a solution, Counting Pine. I wanted to add that PNGOUT does return a 1 in some instances, but only for errors like "file not found".
maybe 1 for not optimized, 2 for find not found, etc.
Awesoken at
I have updated PNGOUT.EXE with your request. It now returns: 0: if the file compressed further 1: if there was an error like 'file not found' 2: if the file was unable to compress further
roytam1 at
Awesoken said at
I have updated PNGOUT.EXE with your request. It now returns: 0: if the file compressed further 1: if there was an error like 'file not found' 2: if the file was unable to compress further
Thank you! It works like a charm!
ace_dent at
Hi Ken
Would it be possible to add another return code to indicate if a bitdepth and/or color reduction was not successful? 3 - Could not reduce color or bit depth.
This would be a massive benefit as I'm trying to make my 'pngslim' script smarter. It seems cleaner than writing temporary files or piping pngout into Find and doing text searches.
Cheers Andrew
Awesoken at
Fixed. Please see the PNGOUT changelog thread.
ace_dent at
Fantastic!! This will be a great help.
Many thanks Andrew
JonoF at
I've also (finally) updated the Linux, BSD, and OSX versions.