4

I want to print an 8bit sRGB PNG image on an Epson TM-T88v receipt printer. The printer needs a 4bit grayscale PNG file to print it correctly.

As I'm using PHP with ImageMagick, I'm not sure which commands are needed to convert the image.

If I use ImageMagick's "identify" and "convert" on the linux console on the 8bit input image I get following output:

test.png PNG 128x128 128x128+0+0 8-bit sRGB 1.78KB 0.000u 0:00.000

I've tried...

convert test.png -depth 4 -colorspace gray test-4bit.png

which gives me still an 8bit image instead of 4bit

test-4bit.png PNG 128x128 128x128+0+0 8-bit sRGB 2.58KB 0.000u 0:00.000

Any suggestions?

  • I tried magick source.png -colorspace gray -depth 4 destination.png using ImageMagick 7.0.7-28 Q16 x64 2018-03-25 and it seems to work. – Endy Tjahjono Nov 6 '18 at 4:23
4

No idea why but identify seems to always assume sRGB. Your image should actually be grayscale. If you use the -verbose option it will report the correct color space.

For the bit-depth you need to explicitly set the color-type and bit-depth for the PNG encoder by using -define.

This should work:

convert test.png -depth 4 -colorspace gray -define png:color-type=0 -define png:bit-depth=4 test-4bit-gray.png
  • Seems to work, thank you! One question: identify -verbose tells me "color: 12".... shouldn't a 4bit per pixel image have 4² = 16 colors? – ninsky Aug 11 '16 at 14:01
  • @ninsky no idea sorry.. my limited tests now give me colors: 16 – Cai Aug 11 '16 at 14:03
  • Just converted another image: "colors" means "used colors" in context of the identified image (not "maximum color space")... so it's ok – ninsky Aug 11 '16 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.