Case helped me (a lot to) create a script that uses following programs to optimize the size of png files:
You need to download these programs and put them in path (windows dir etc.) to use the script.
The script uses a little tool (sizecmp.exe included in the zip) Case made to compare the size of the original and optimized file to save the smallest file (when the optimizer can't do this on its own); put this in path too.
With this script (megaopt.bat) you should be able to optimize your png files as much as possible (some times it can help to run it twice though). Be aware that it will take a long time on complex things like screenshots.
You use the script like this:
CODE
megaopt file1.png file2.png file3.png
from dos-prompt.
Or you can make a .bat file like this you can run in a dir with png files:
CODE
@echo off
for %%i in (*.png) do call megaopt "%%i"
This requires megaopt.bat to be in the same dir or in path.
Using this should be lossless but don't complain to me if the optimizers do something funny. The original png WILL BE OVERWRITTEN!
Florian
Dec 7 2003, 22:11
Jan, thank you very much!
Using you script stripped 120 KB from my program's screenshots

~ Florian
JensRex
Dec 31 2003, 15:17
May I suggest running pngcrush with the following options:
pngcrush.exe -brute -l 9 -rem alla
It makes it a bit more efficient.
Edit: OMFG... pngout is SLOW!
Nice! Same thing for GIF files please...
westgroveg
Jan 1 2004, 03:31
Frontend anyone?
RIV@NVX
Jan 1 2004, 12:49
QUOTE (Cobra @ Dec 31 2003, 08:38 PM)
Nice! Same thing for GIF files please...
Why would anyone prefer GIF over PNG?
Very nice! My site is now 33KB smaller because of it (16 images, so approximately 2KB per image).
QUOTE (RIV@NVX @ Jan 1 2004, 12:49 PM)
QUOTE (Cobra @ Dec 31 2003, 08:38 PM)
Nice! Same thing for GIF files please...
Why would anyone prefer GIF over PNG?
I prefer PNG but sometimes i have to use evil GIFs...
JensRex: Thank you. I will take a look at that soon.
About GIF: I have never seen any kind of optimizer for GIF.... And I wonder if it is possible since GIF is lossy and png is not.
About frontend: There's no frontend but it shouldn't be hard to make one though I don't understand why you need it really. Just running a file in a dir seems very simple.
The program
PNGGauntlet is a frontend for PNGOut and PNGRewrite.
eltoder
Jan 2 2004, 09:43
QUOTE (Jan S. @ Jan 2 2004, 04:21 AM)
About GIF: I have never seen any kind of optimizer for GIF.... And I wonder if it is possible since GIF is lossy and png is not.
GIF is lossless, but it only supports up to 256 colors. But it uses LZW for compression, so it has a low potential for lossless optimization.
-Eugene
NeoRenegade
Jan 4 2004, 16:52
I get errors about an invalid switch /Q, and AdvaLame seems to only flash for a moment. Aside from that it seems to work.
Can you give me a file where there are problems?
NeoRenegade
Jan 6 2004, 19:26
No, sorry... that AdvaLame flashing seemed to only have happened the first time or two anyway.
The thing about /Q being invalid is constant, though. I'm not well-aversed in DOS scripting... what does the /Q do?
QUOTE (NeoRenegade @ Jan 6 2004, 07:26 PM)
The thing about /Q being invalid is constant, though. I'm not well-aversed in DOS scripting... what does the /Q do?
it means you are not prompted to conferm the deletion.
I don't know what would cause you to get an error.
NeoRenegade
Jan 7 2004, 13:44
Ah... so I suppose I can get rid of the /Q's from the script, then? It will only make it prompt me to delete files?
Figures, even DOS acts drunk on my system.
Thanks for helping me out.
NeoRenegade
Jan 7 2004, 14:13
I've got an idea... since I have some doubt the program is doing the job as intended... would you mind sending me a half-dozen (or so) unoptimized PNG images?
Then we can compare my results to yours to verify that the script is at least performing properly on my system.
QUOTE (NeoRenegade @ Jan 7 2004, 01:44 PM)
Ah... so I suppose I can get rid of the /Q's from the script, then? It will only make it prompt me to delete files?
Figures, even DOS acts drunk on my system.
Thanks for helping me out.
/q is used to delete temp files. So it would make little sense to bother with them every time

We need to make temp files since some optimizers don't allow just optimizing the files. they just output their best shot.
QUOTE (NeoRenegade @ Jan 7 2004, 02:13 PM)
I've got an idea... since I have some doubt the program is doing the job as intended... would you mind sending me a half-dozen (or so) unoptimized PNG images?
Then we can compare my results to yours to verify that the script is at least performing properly on my system.
If I can find such thing on my HD

I attached some files you can try though these are not good examples of what you can compress very much.
QUOTE (Cobra @ Dec 31 2003, 07:38 PM)
Nice! Same thing for GIF files please...
I found this:
http://www.gold-software.com/ago.shtml
Override
Jan 8 2004, 19:35
QUOTE (NeoRenegade @ Jan 4 2004, 04:52 PM)
I get errors about an invalid switch /Q, and AdvaLame seems to only flash for a moment. Aside from that it seems to work.
I also get the /q-errors, although the script seems to be getting the job done anyway. OS installed is Windows 98 SE, maybe that has something to do with it?
try writting "del /?" in dos prompt and see if /Q is not listed as a valid switch.
Override
Jan 9 2004, 17:40
The only valid switch on my system seems to be /P, which prompts the user for confirmation before deleting.
NeoRenegade
Jan 9 2004, 19:46
CODE
Deletes one or more files.
DEL [drive:][path]filename [/P]
ERASE [drive:][path]filename [/P]
[drive:][path]filename Specifies the file(s) to delete. Specify multiple files by using wildcards.
/P Prompts for confirmation before deleting each file.
Seems like there is a difference between windows versions then.
2000 and XP has the /Q switch.
What happens if you remove the /Q? if it doesn't prompt you, you should just use that.
QUOTE (Jan S. @ Jan 9 2004, 07:09 PM)
Seems like there is a difference between windows versions then.
Yes. That's why you should use the file extension
.cmd for 2k/XP and
.bat for the ol' DOS-based 9x. There are differences in both available commands and syntaxes. For example, the "choice" command doesn't work anymore under 2k/XP, but it can easily be reconstructed with SET and IF.
Althalus
Jan 18 2004, 03:29
Thank You Jan and Case for a excellent utility.
-----------
Edit: When first tested the tool, I only used filename.png and it worked wonderfully. But when wanted to use it for real, it choked on the first file

and just about every single .PNG I have will b0rk it, hehe
It breaks at files that contain spaces. Anyone else got this problem? (tried both the directory solution that Jan posted, and the vanilla megaopt.bat)
CODE
C:\DOWNLO~1>megaoptDir
C:\DOWNLO~1>for %i in (*.png) do call megaopt "%i"
C:\DOWNLO~1>call megaopt "Snap 3.png"
3.png""=="" was unexpected at this time.
CODE
C:\DOWNLO~1>megaopt "Snap 3.png"
3.png""=="" was unexpected at this time.
Jan S.
Jan 18 2004, 19:33
Thank you. Case fixed it. First line changed.
Please redownload file from first post.
Althalus
Jan 19 2004, 12:43
Awesome, thanks!
kode54
Mar 10 2004, 00:10
I usually only use optipng and advpng/advdef. Then I use
TweakPNG for manual adjustments and/or inspection.
I also have my own resizing tool, which also saves in index mode if the image has 256 colors/alpha combinations or less. It also sorts the palette by luminance on output, or if alpha is present, by luminance and then alpha. It can also be commanded to not resize at all, so it only performs color reduction.
I am not sure if any of the above tools reorder the palette so that the tRNS chunk can be reduced, since I know that optipng and advpng fail in this respect.
Unfortunately, I cannot publish this tool, because I use a shareware image manipulation library without a license.
Daijoubu
Mar 11 2004, 17:02
Get rid of pngcrush, worthless (sorry pngcrush devellopers...)

optipng is fast and *always* gives better results
pngout is the best but is much slower (doesn't relay on the pnglib, the autor have written it own lib)
I have 2 versions of pngout, the lastest and the one from PNGGauntlet (GUI of pngrewrite/pngout)
Sometimes, the one from PNGGauntlet gives better results (older version, doesn't touch the pallette, should be the same as using some switch with the newer versions)
PNGrewrite+PNGout isn't always the best, it's sometimes smaller without PNGRW
Haven't tried advpng yet...
For examle: HA logo.png: with megaopt: 3,064 bytes
PNGrewrite+PNGout*2 (lastest) = 2,998 bytes
You should perhaps make it possible to drag and drop in the bat file (%1)
Or even prompt the user for filename

Edit: weird, can't seem to be able to drag and drop
Mr_Rabid_Teddybear
Sep 14 2004, 17:33
Sorry for reviving an ancient thread, but I've been using this script on and off; it's great but I have one problem:
It goes into an endless loop (18 hours on an 18 Kb file can't be right), so after it's gone through 3 or 4 passes I just abort it while pngout are at it. The image are much smaller and in mint condition, nice, but I would prefer that it stopped by itself.....
rutra80
Sep 14 2004, 20:28
I took a look at the script and saw that pngout isn't used with all its possibilities - two switches can improve compression quite a lot - /f and /b. By default, pngout uses /f0 for paletted images and /f5 for 24bit ones, but often that default behaviour doesn't give the best results - sometimes /f0 performs better on 24bit images and /f5 on paletted ones, so both cases should be tested by the script. Then the /b switch should be tested, by default pngout uses /b256, but I saw many times that other values increase compression. Values to try are power of 2 including 0, so: 0, 1, 2, 4, 8, 16, 32, 64, 128, 512, 1024 and perhaps more.
I could try to improve that script myself but I'm not quite familiar with command-line scripts...
Cablestein
Jan 18 2005, 19:57
I have a question...
Why does PNGRewrite occur in the middle of the batch file?
Shouldn't PNG Rewrite be the very first thing that is run before all the crushers?
I read somewhere the PNG Rewrite only re-sorts the palette to be more efficient... and that it doesn't do any kind of re-compression.
Also, I agree with PNGOut needing more exploration... it has many possibilities. In terms of time... what difference does a few seconds more of processing mean.
sven_Bent
Jan 18 2005, 23:12
my testing showes that using pnfrewrite always results in af bigger file,
i only use pngout and advpng
i have a batchfiles the tries to find the smalle pngout filer by using 4 different filtera methods (f0+f1+f2+f5) and the samlels arethen retried with 5 differenet chunksize rangin from 128 to 512.
The finel result are then passed on to advpng to se if it can make it even smaller
Cablestein
Jan 25 2005, 17:09
I made a shortcut in my quicklaunch bar where I just drag a folder into it and badda-boom CRUUUSH. Pretty handy. I got tired of going to a prompt and typing in the same command(s) over and over.
I made a little icon for it too. Some teeth biting down on the letters "PNG".
In doing this drag-n-drop thing I discovered I've been using Megaopt the wrong way for months. I've been using "Megaopt *.png" all this time, but I looking into the DOS output I saw that the process ends at PNGRewrite! PNGRewrite doesn't like that basic wildcard thing. Using that line in the original post of this thread, works... I should've read everything... =).
CRUUUUUUSH
KILLLLLLL DESSSTROY
counting_pine
Jan 29 2005, 01:50
Try this batch file instead:
@echo off
copy %1 %1.backup
advpng -z -4 %1
optipng -o7 %1
advdef -z -4 %1
pngout %1
It doesn't need to do size comparisons, because none of these programs (at least, the latest versions) will write larger PNGs unless specifically asked to.
It doesn't do PNGRewrite, because basically all it does is optimise the palette, which OptiPNG does anyway.
Nor does it do PNGCrush, because OptiPNG does the same thing as PNGCrush, only it has more features and is more efficient.
This batch file will back up the original PNG, of course you can stop that by removing the copy line.
I think this is the best order to run the programs;
AdvPNG should remove any unnecessary chunks from the PNG file, refilter and recompress the IDAT with the 7-Zip Deflate method. It only works on colour PNGs (types 2,3,6).
OptiPNG will try and change the colour type to reduce the image size, and will find the best combination of IDAT filter type and ZLib Deflate method.
AdvDef will simply try to recompress the IDAT with the 7-Zip Deflate method. It won't refilter it, but use the best filter type found by OptiPNG (Assuming OptiPNG modified the file).
PNGOut will refilter the IDAT and recompress it using its own special Deflate algorithm. It will remove any unnecessary chunks, if AdvPNG hasn't already. It uses the slowest algorithm, but often gets the best results.
Notes:
1. Refiltering the IDAT may not make it compress more; I think OptiPNG is the only one that tries various filter types to find the best one, and all the others try just the one it thinks will be best, except for AdvDef, which recompresses the IDAT how it was already filtered.
2. This order of programs might not be optimal for some PNGs. For example, AdvDef might work better with PNGOut's chosen filter type. Running it again may squeeze out a few more bytes. Alternatively, it would be quicker, and probably as effective, to just repeat the AdvDef command after PNGOut.
3. OptiPNG and PNGOut have a few more options to play around with. You might be able to compress your PNG a bit more with a little experimentation.
counting_pine
Jan 29 2005, 03:50
Re GIFs:
If it's not animated, you can probably make it smaller by converting it to PNG. I suggest using PNGOut; it can convert various types to PNG, including GIFs, BMPs, JPGs, and pictures on the clipboard.
If you want to optimise a GIF, try
Trout's GIF Optimizer. It's freeware. It also takes various other input types (not PNG). Be careful you don't accidentally reduce the palette though.
JensRex
Jan 29 2005, 13:36
I made another batch file some time ago, which I refined lately. It attempts to be user friendly, having help text, safety checks and progress information, while still being advanced, having --insane switch making pngout optional because it's extremely slow, and ability to batch optimize many files in one go.
Check it out
here. Let me know what you think. I haven't gotten much feedback on it.
nottoday
Jul 8 2009, 08:30
hi there,
I can't download the megaopt.zip attached file!
I am a new man.
Anyon tell me what i have to do to download it ?
thanks,
nottoday
pepoluan
Jul 9 2009, 17:42
QUOTE (nottoday @ Jul 8 2009, 14:30)

hi there,
I can't download the megaopt.zip attached file!
I am a new man.
Anyon tell me what i have to do to download it ?
thanks,
nottoday
Try counting_pine's batch file instead (you have to create it manually using Notepad)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.