Linux – Convert image to uncompressed PNG from the command-line

command lineconversionimageslinuxpng

I have a compressed PNG image compressed.png. I can convert it to an uncompressed PNG decompressed.png using GIMP (saving as PNG and setting compression level to 0). How can this be done on the command line (Linux)?

I recall doing this in the past using Imagemagick's convert, but I forgot how. I tried some things that I thought should work based on the documentation:

  • convert compressed.png -compress None decompressed.png
  • convert compressed.png +compress decompressed.png
  • convert compressed.png -quality 0 decompressed.png
  • convert compressed.png -quality 00 decompressed.png

just wrote an ordinary compressed PNG.

Aside: why would you want an uncompressed PNG?

Some cases:

  • You want to support efficient (binary) diffs of the image data, while still using other features of the PNG format (as opposed to storing raw image data or BMP).
  • You want to compress several PNGs together in a tarball or 7z archive, but want to keep using PNG features. If the images are sufficiently similar this can give a better compression ratio than compressing individually.
  • Useful as a baseline size for testing PNG optimizers.

Best Answer

ImageMagick will always compress PNG files. The worst compression you can get is using:

convert -verbose -quality 01 input.png output.png

but it depends on the image content (the 0 will use Huffman compression which sometimes compress better than zlib).

You can try other tools like pngcrush (http://pmt.sourceforge.net/pngcrush/) to disable the compression:

pngcrush -force -m 1 -l 0 input.png output.png

which create a file the same size GIMP create when using Compression Level 0 (few bytes more or less).

Some example sizes (for a photographic PNG, 1600x1200):

  • original: 1,693,848 bytes.
  • after IM: 2,435,983 bytes.
  • after GIMP: 5,770,587 bytes.
  • after pngcrush: 5,802,254 bytes.
Related Question