Monochrome text

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
cja
Posts: 4
Joined: 2015-01-13T04:34:13-07:00
Authentication code: 6789

Monochrome text

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Monochrome text

Post 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
snibgo's IM pages: im.snibgo.com
cja
Posts: 4
Joined: 2015-01-13T04:34:13-07:00
Authentication code: 6789

Re: Monochrome text

Post by cja »

I do not see a difference when putting -monochrome behind the label option.
Switching dithering off is an improvement.

Thanx!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Monochrome text

Post 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.
snibgo's IM pages: im.snibgo.com
cja
Posts: 4
Joined: 2015-01-13T04:34:13-07:00
Authentication code: 6789

Re: Monochrome text

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Monochrome text

Post by snibgo »

Ah, I understand your thinking. You may be correct. I don't know.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Monochrome text

Post 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
snibgo's IM pages: im.snibgo.com
cja
Posts: 4
Joined: 2015-01-13T04:34:13-07:00
Authentication code: 6789

Re: Monochrome text

Post by cja »

Yep. That seems to do the trick. Thanx!
Post Reply