Page 1 of 1

Monochrome text

Posted: 2015-01-13T04:42:55-07:00
by cja
I want to create a monochrome bitmap with good quality text on it. Using a bit depth of 8, the text comes out very nicely. Making that into
a monochrome bitmap is terrible.

Commands I have been using (with variations):

Code: Select all

convert -background black -fill white -size x30 -density 192 label:"Text" sample.png
The above gives a good result, but bit-depth 8.

Code: Select all

convert -background black -fill white -size x30 -density 192 -monochrome label:"Text" sample_mono.png
The above gives a horrible result, but bit depth 1

I don't want to convert a grayscale image to monochrome, but instruct imagemagick to render the text directly in black/white. Looking at some freetype examples, that should give a good quality. But how to do that with imagemagick?

Re: Monochrome text

Posted: 2015-01-13T05:57:32-07:00
by snibgo
"-monochrome" should come after label, not before.

By default, when IM reduces colours, it dithers. For this purpose, a better result comes when dithering is turned off.

Code: Select all

convert -size x30 label:"Text" +dither -monochrome x.png

Re: Monochrome text

Posted: 2015-01-13T07:18:22-07:00
by cja
I do not see a difference when putting -monochrome behind the label option.
Switching dithering off is an improvement.

Thanx!

Re: Monochrome text

Posted: 2015-01-13T07:30:35-07:00
by snibgo
Moving "-monochrome" makes no difference to this command. If the command was more complex, it would. The idea is to create an image, process it, and finally save it. Specifying the processing before creating the image sometimes works, but in general it doesn't.

Re: Monochrome text

Posted: 2015-01-13T08:24:39-07:00
by cja
My thinking to put it 'before' the processing was to enable the rendering step for the text to take into account the output is monochroom. Thereby it could potentially optimize the output taking this into account.

For example, in freetype there is "FT_LOAD_TARGET_MONO" (1) that impacts the rasterization/rendering and gives great text output. I hoped to get the same quality with convert and avoid using freetype, or something simialr, directly.

(1) http://www.freetype.org/freetype2/docs/ ... TARGET_XXX

Re: Monochrome text

Posted: 2015-01-13T09:13:24-07:00
by snibgo
Ah, I understand your thinking. You may be correct. I don't know.

Re: Monochrome text

Posted: 2015-01-13T09:19:29-07:00
by snibgo
From the code in annotate.c, it seems that FT_LOAD_TARGET_MONO is activated when anti-aliasing is off. That option certainly should be before label:

Code: Select all

convert -size x30 +antialias label:"Text" x.png

Re: Monochrome text

Posted: 2015-01-13T15:01:03-07:00
by cja
Yep. That seems to do the trick. Thanx!