Reduce bit-depth of PNG files from the command line
Asked Answered
D

2

6

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

I have an OSX based system at my disposal and am familiar with the find command so am really more keen to to locate a suitable PNG utility command.

Discriminator answered 25/8, 2009 at 17:51 Comment(0)
R
3

AFAIK the only PNG format that supports the alpha layer is PNG-24; Reducing the PNG to another format may require specifying a transparent color in a CLUT, which will not give you the output you want.

From the feature list on PNG's website:

  • 8- and 16-bit-per-sample (that is, 24- and 48-bit) truecolor support
  • full alpha transparency in 8- and 16-bit modes, not just simple on-off transparency like GIF

... which I read to mean that anything other than PNG-24 or PNG-48 does not support full alpha transparency.

Rosaliarosalie answered 25/8, 2009 at 17:58 Comment(2)
Thanks - I was unaware of this PNG limitation so you have saved me some time.Discriminator
@Discriminator Paletted PNGs do support full alpha transparency, see pngquant.orgAlloy
A
6
  1. Install fink

  2. Say "fink install imagemagick" (might be "ImageMagick")

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

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

  5. Optional: "fink install pngcrush" and run that as a second pass after the convert pass.

Auroreaurous answered 25/8, 2009 at 17:58 Comment(0)
R
3

AFAIK the only PNG format that supports the alpha layer is PNG-24; Reducing the PNG to another format may require specifying a transparent color in a CLUT, which will not give you the output you want.

From the feature list on PNG's website:

  • 8- and 16-bit-per-sample (that is, 24- and 48-bit) truecolor support
  • full alpha transparency in 8- and 16-bit modes, not just simple on-off transparency like GIF

... which I read to mean that anything other than PNG-24 or PNG-48 does not support full alpha transparency.

Rosaliarosalie answered 25/8, 2009 at 17:58 Comment(2)
Thanks - I was unaware of this PNG limitation so you have saved me some time.Discriminator
@Discriminator Paletted PNGs do support full alpha transparency, see pngquant.orgAlloy

© 2022 - 2024 — McMap. All rights reserved.