Reduce the bit depth of PNG files from the command line

What command or series of commands could I execute from the CLI to recursively traverse the directory tree and reduce the bit depth of all PNG files in this tree from 24bpp to 16bpp? Commands should preserve the alpha layer and should not increase the size of the PNG file - in fact, reduction would be preferable.

I have an OSX-based system and am familiar with the find , so I am very interested in finding a suitable PNG utility command.

+4
source share
2 answers

AFAIK the only PNG format that supports the alpha layer is PNG-24; To reduce PNG to another format, you may need to specify a transparent color in CLUT, which will not give you the result you need.

From the list of functions on the PNG website:

  • 8- and 16-bit fetch (i.e. 24- and 48-bit) truecolor support
  • full alpha transparency in 8- and 16-bit modes, not just transparent transparency like GIF

... which I read to mean that nothing but PNG-24 or PNG-48 supports full alpha transparency.

+2
source
  • Install fink

  • Say "fink install imagemagick" (maybe "ImageMagick")

  • "convert -depth 16 old / foo.png new / foo.png"

  • If you did what you want, wrap it in a search call and be happy. If not, say "convert -help" and RTF-ImageMagick-M. :)

  • Optional: "fink install pngcrush" and run it as the second pass after the envelope.

+3
source

All Articles