Page 1 of 1

Font rendering

Posted: 2009-06-09T03:17:25-07:00
by jkmaster
Hello,

I'm trying to recreate the appearance of the standard Windows GUI font, which is Microsoft Sans Serif 12pt at the standard 72ppi resolution.

The command line input I came up with is

Code: Select all

convert -fill black -font Microsoft-Sans-Serif -density 72 -pointsize 12 +antialias label:"My test text" test.png
Some details of the resulting text are different to what I'm used to from Windows. For example, the lowercase 's' misses the two pixels in its center:

Code: Select all

;    ss          ss
;   s  s        s  s
;    s     
;     s 
;   s  s        s  s
;    ss          ss 

;  Windows  Imagemagick
I think one should get my point from my text representation ... Maybe someone knows how to change the input for better results? I already tried to take multiples/fractions of the density and pointsize values.

Best Regards,
jk

Re: Font rendering

Posted: 2009-06-10T01:00:15-07:00
by anthony
I would start by adding the debug option: -debug annotate and then use -annotate on any image with that font. This will let you check that the font you specified is actually being found, and IM is not just falling back to some default font.

Re: Font rendering

Posted: 2009-06-14T23:54:51-07:00
by jkmaster
I'm sorry I didn't reply earlier, but there was a public holiday last Thursday and a very long weekend ... Anyway, thank you for your advice, Anthony.

With the -debug option, the output is

Code: Select all

convert: unrecognized event type `-fill' @ convert.c/ConvertImageCommand/1047.
When I remove the -fill option, Imagemagick prints the same message for the -font option. I'm not sure whether that output is some general error or if it really stems from options that cannot be interpreted?

Maybe the version I'm using is relevant: 6.5.2-0 2009-05-01 Q16 OpenMP, in conjunction with Windows XP SP2.

Best Regards,
jk

Re: Font rendering

Posted: 2009-06-14T23:58:18-07:00
by anthony
That should be -debug annotate
Note the extra argument following the -debug option.

Re: Font rendering

Posted: 2009-06-17T05:15:26-07:00
by jkmaster
Thanks once again, Anthony. I needed some time to try out some more options, including -annotate as you suggested. Here's my latest input:

Code: Select all

convert test1.png -debug annotate -font Microsoft-Sans-Serif -gravity center -density 72 -pointsize 12 +antialias -annotate 0 "My test text" test1_out.png
and the debug output says,

Code: Select all

2009-06-17T14:00:22+02:00 0:01 0.547u 6.5.2 Annotate convert[1008]: annotate.c/RenderFreetype/1459/Annotate
  Font c:\windows\fonts\micross.ttf; font-encoding none; text-encoding none; pointsize 12
2009-06-17T14:00:22+02:00 0:01 0.547u 6.5.2 Annotate convert[1008]: annotate.c/GetTypeMetrics/1001/Annotate
  Metrics: text: My test text; width: 55; height: 14; ascent: 12; descent: -3; max advance: 16; bounds: -1,-2  10,9; origin: 54,0; pixels per em: 12,12; underline position: -3.4375; underline thickness: 1.59375
2009-06-17T14:00:22+02:00 0:01 0.547u 6.5.2 Annotate convert[1008]: annotate.c/RenderFreetype/1459/Annotate
  Font c:\windows\fonts\micross.ttf; font-encoding none; text-encoding none; pointsize 12
I don't have many experience with reading the debug information, but it seems ok to me, and obviously the font file (c:\windows\fonts\micross.ttf) has been identified correctly. However, the result is the same as before :(

Meanwhile I tried keeping antialiasing switched on and using -level to modify the gamma level (all I need is black & white output, nothing in between), but that didn't improve the results. Any recommendations to make the text output look more like the appearance on Windows dialogs?

Best Regards
jk

Re: Font rendering

Posted: 2009-06-17T22:33:03-07:00
by anthony
Prehaps try using -threshold 50% or some other level to get pure black and white pixels.

-threshold 0 will only keep the pure black pixels

-negate -threshold 0 -negate will only keep pure white pixels.

See IM Examples, Threshold
http://www.imagemagick.org/Usage/quantize/#threshold