1

I'm trying to convert (several) PNG files to an indexed black and white (1-bit) palette image in linux via a bash script (or C code). If I use Gimp and take menu options Image, Mode, Indexed I get the "Indexed Colour conversion" dialog and can select "Use black and white (1-bit) palette" and "Remove unused and duplicate colors from colormap" options. If I then export the file I get a desired (black and white) indexed file. I want to do this via bash or part of code (preferably c).

I've tried using a imagemagick convert with threshold of 50% this looks approx like what I want bit the output is greyscale not indexed.

kalpha
  • 45
  • 7
  • Does this do what you want? `convert lena.png -threshold 50% PNG8:x.png` – fmw42 Nov 13 '20 at 17:07
  • @fmw42 it does convert to indexed, but it has a bit depth of 8 which is not the 1-bit palette GIMP produces. Do you happen to know how to create a 1-bit indexed png? I tried `PNG1:x.png`, `-depth 1 -colors 2` and `-format PNG1`, neither of which worked – asdf101 Nov 14 '20 at 20:47
  • 1
    try `convert logo: -threshold 50% -define png:color-type=3 -define png:bit-depth=1 logo_1.png` otherwise, I do not know. – fmw42 Nov 14 '20 at 21:27
  • @fmw42 thanks, that worked! Thought I had already tried that but apparently not – asdf101 Nov 14 '20 at 21:44

0 Answers0