14

When I try to run a bunch of PNG-8 images with alpha transparency through Imagemagick, it converts them to PNG-32, increasing the file size a lot.

Is it possible to force Imagemagick to keep my image type as 8-bit PNG?

mager
  • 4,813
  • 8
  • 29
  • 30

2 Answers2

20

You can do it like this:

convert test.png PNG8:test2.png

I've had varying luck with IM and PNG8, but this is the correct way to do it.

Matthew Talbert
  • 5,998
  • 35
  • 38
  • How do we use this ? Can you share any example – Ahmad Arslan Apr 20 '15 at 06:15
  • That *is* an example. What are you looking for? – Matthew Talbert Apr 22 '15 at 00:19
  • 2
    Keep the format list under your pillow: http://www.imagemagick.org/script/formats.php – Ciro Santilli OurBigBook.com Sep 28 '15 at 09:35
  • so if I use convert test.png PNG24:test2.png can it convert an image with bit depth of 32 to 24? – Mona Jalal May 10 '17 at 22:47
  • 1
    It seems that this method destroys any partial transparency in the image, even though the PNG format supports colormapped images with semitransparent colors. The only way I know of to preserve such partial transparency, while still obtaining 8-bit colormapped output, is to tell ImageMagick to output PNG32 images and [re-quantize them with pngquant](https://stackoverflow.com/a/14032098). – Ilmari Karonen Jun 18 '17 at 17:17
10

I seem to get the best result using the following

convert src.png -colors 256 PNG8:dest.png
scarba05
  • 2,943
  • 1
  • 27
  • 29
  • To go from a B&W PNG to an 8-bit color PNG, `-colors 256` is what worked for me on ImageMagick 6.8.7-7 – Carlos Scheidegger Feb 23 '14 at 19:38
  • This may be the best option if you have more than 256 colours in there, as it will do a proper reduction. The answer without -colors doesn't do this. – GreenReaper Mar 10 '15 at 04:47
  • `-depth 8` produces the best result on ImageMagick 7. Both `-colors 255` and `PNG8:` results has too much artifacts. – Ben Mack Nov 03 '19 at 12:16