pngcrush is an optimizer tool for PNG (Portable Network graphic) files. pngcrush is an excellent batch-mode compression utility for PNG images. Depending on the application that created the original PNGs, it can improve the file size anywhere from a few percent to 40% or more (completely losslessly). It reduces the size of the PNG IDAT datastream by trying various compression levels of PNG filter methods. It also can be used to remove unwanted ancillary chunks, or to add certain chunks including gAMA, tRNS, iCCP, and textual chunks and it can fix incorrect gamma info written by Photoshop 5.0 as well as the erroneous iCCP chunk written by Photoshop 5.5.
pngcrush is a command line tool and can run on Linux, UNIX and Windows
Install pngcrush
To install pngcrush, click this 1-click installer from Packman supported on openSUSE 11.1/11.0/10.3/10.2
NOTE: Click here for a how to on enabling 1-click install in openSUSE 10.2
This should download the YMP file and automatically launch the YaST package manager to add the required Repositories and download and install pngcrush and the dependencies. Click next on the pngcrush installation screen and Next again on the installation proposal window. This should start adding the required repositories, download and install pngcrush and its required dependencies. Click Finish when the installation completes successfully.
This installs pngcrush under /usr/bin
opensuse11:~ # which pngcrush
/usr/bin/pngcrush
In its simplest form, you run png crush with a source file and a destination file as follows:
opensuse11:~ # pngcrush bluediving1.png out.png
| pngcrush 1.6.13
| Copyright (C) 1998-2002,2006-2008 Glenn Randers-Pehrson
| Copyright (C) 2005 Greg Roelofs
| This is a free, open-source program. Permission is irrevocably
| granted to everyone to use this version of pngcrush without
| payment of any fee.
| Executable name is pngcrush
| It was built with libpng version 1.2.34, and is
| running with libpng version 1.2.34 – December 18, 2008| Copyright (C) 1998-2004,2006-2008 Glenn Randers-Pehrson,
| Copyright (C) 1996, 1997 Andreas Dilger,
| Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,
| and zlib version 1.2.3.3, Copyright (C) 1998-2002 (or later),
| Jean-loup Gailly and Mark Adler.
| It was compiled with gcc version 4.3.2 [gcc-4_3-branch revision 141291].Recompressing bluediving1.png
Total length of data found in IDAT chunks = 36377
unknown chunk handling done.
IDAT length with method 1 (fm 0 zl 4 zs 0) = 35211
IDAT length with method 2 (fm 1 zl 4 zs 0) = 38033
IDAT length with method 3 (fm 5 zl 4 zs 1) = 37423
IDAT length with method 4 (fm 0 zl 9 zs 1) = 34954
IDAT length with method 7 (fm 0 zl 9 zs 0) = 33410
Best pngcrush method = 7 (fm 0 zl 9 zs 0) for out.png
(8.16% IDAT reduction)
(8.26% filesize reduction)CPU time used = 0.160 seconds (decoding 0.040,
encoding 0.120, other 0.000 seconds)
If you want to perform a batch compression then simply specify the files (can use wildcards) and specify extensions (-e) for output files and may be a output directory with -d option. For instance, here I’m optimizing all my PNG files from the current folder to a folder called pics as follows:
opensuse11:~ # pngcrush -d pics -e out.png *.png
In the above command, “-d pics” specifies that the output is directed to the pics directory and “-eout.png” appends out.png to all the output files.
For more advanced options and help, simply run “pngcrush” without any arguements
opensuse11:~ # pngcrush
…
..
.usage: pngcrush [options] infile.png outfile.png
pngcrush -e ext [other options] files.png …
pngcrush -d dir [other options] files.png …
options:
-already already_crushed_size [e.g., 8192]
-bit_depth depth (bit_depth to use in output file)
-brute (use brute-force: try 126 different methods [11-136])
-c color_type of output file [0, 2, 4, or 6]
-d directory_name (where output files will go)
-double_gamma (used for fixing gamma in PhotoShop 5.0/5.02 files)
-e extension (used for creating output filename)
-f user_filter [0-5]
-fix (fix otherwise fatal conditions such as bad CRCs)
-force (write a new output file even if larger than input)
-g gamma (float or fixed*100000, e.g., 0.45455 or 45455)
-huffman (use only zlib strategy 2, Huffman-only)
-iccp length “Profile Name” iccp_file
-itxt b[efore_IDAT]|a[fter_IDAT] “keyword”
-keep chunk_name
-l zlib_compression_level [0-9]
-loco (“loco crush” truecolor PNGs)
-m method [0 through 200]
-max maximum_IDAT_size [default 8192]
-mng (write a new MNG, do not crush embedded PNGs)
-nofilecheck (do not check for infile.png == outfile.png)
-n (no save; does not do compression or write output PNG)
-plte_len n (truncate PLTE)
-q (quiet)
-reduce (do lossless color-type or bit-depth reduction)
-rem chunkname (or “alla” or “allb”)
-replace_gamma gamma (float or fixed*100000) even if gAMA is present.
-res dpi
-rle (use only zlib strategy 3, RLE-only)
-save (keep all copy-unsafe chunks)
-srgb [0, 1, 2, or 3]
-ster [0 or 1]
-text b[efore_IDAT]|a[fter_IDAT] “keyword” “text”
-time_stamp
-trns_array n trns[0] trns[1] .. trns[n-1]
-trns index red green blue gray
-v (display more detailed information)
-version (display the pngcrush version)
-w compression_window_size [32, 16, 8, 4, 2, 1, 512]
-z zlib_strategy [0, 1, 2, or 3]
-zmem zlib_compression_mem_level [1-9, default 9]
-zitxt b[efore_IDAT]|a[fter_IDAT] “keyword”
-ztxt b[efore_IDAT]|a[fter_IDAT] “keyword” “text”
-h (help and legal notices)
-p (pause)
Click here to visit the project homepage.
It is also possible to reduce size of png images using imagemagick in a lossy way (but often not noticeable) and then running optipng or pngcrush as a last step:
For example:
# Reduce depth to 4 bits and strip comments with
# imagemagick command line, then run optipng
$ convert -strip -depth 4 foo.png foo.png
$ optipng -o9 foo.png foo.png
if i have a digikam tag in the image just using “pngcrush image_with_tag.png crushed_image.png” will result in the loss of my digikam tag, which is not so nice. all digikam settings are set to save the addition informaiton in the file. so if I just copy my image the tag shows up nicely in digikam. is there a way to keep the tags with pngcrush?
best regards robin
> is there a way to keep the tags with pngcrush?
Can you try with optipng instead of pngcrush?
See http://optipng.sourceforge.net/
optipng does not lose any information as far as I know.
I’m not sure what “digikam tag” is, but I assume that’s
a comment in the image (which should not be removed by
optipng).
Does anybody know a decent tool for reducing .jpg files (preferibly converting them to png). I’ve checked optipng out but its supported external files does not include .jpg. I need a reduction as lossless as possible.