For printing images on a Epson TM-T88v receipt printer, I had to convert a PNG file to a 4-bit grayscale PNG by using ImageMagick.

Using the following command I'm getting pretty good results except of a white border around certain parts of the converted image:

convert test.png -depth 4 -colorspace gray -define png:color-type=0 -define png:bit-depth=4 test-4bit-gray.png

Original input image:

Original image

Converted image:

Converted image with ImageMagick

If I use Epson's native JS library to convert PNG images to 4-bit grayscale I get following result which looks way smoother:

Converted image with native Epson library

Which ImageMagick options could help me to avoid the white border around the heart eyes of the Emoji or make it to look smoother at all?

  • Looks like an anti-aliasing issue to me. I never use imagemagic, so I'm not sure if/how to adjust those settings, but if you do, start there. On second thought, you could increase your bit depth. That might help. increase it to 8-24, if you can. – Manly Aug 11 '16 at 15:01
  • @Manly, thanks. Need to have exactly a 4-bit depth. The Epson example has also 4-bit. Will look for an anti-aliasing option... – ninsky Aug 11 '16 at 15:05
  • 1
    What you want is some dithering – Cai Aug 11 '16 at 15:12

What you need is some dithering. There is some information on dithering techniques using ImageMagick here:

Using -ordered-dither for the dither and removing the alpha gets you pretty close:

Dithered 4Bit Grayscale Conversion with ImageMagick

Converted with:

convert test.png -depth 4 -colorspace gray -alpha remove -ordered-dither o2x2,16 -define png:color-type=0 -define png:bit-depth=4 test-4bit-gray.png

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.