Page 1 of 1

MagickQueryFontMetrics() differs from command line

Posted: 2007-01-24T08:33:12-07:00
by vav
Hi,

I convert text to image both from command line and using MagickWand API.
I noticed difference for some fonts.
Here's an example, try to generate image for text, say "7", using this font:
http://www.atwss.com/vav/trikotnr1.ttf

For pointsize = 300, command line produces 187x251 pixels image, API returns size 187x352. Moreover vertical shift is different. I take into account text descender, when drawing text from API.
Here's example images,
for command line: http://www.atwss.com/vav/7.png
and for API: http://www.atwss.com/vav/test1.png

Posted: 2007-01-25T06:16:45-07:00
by magick
To account for the difference in your text rendering we would need to see your command line as well as your API source code.

Posted: 2007-01-25T07:48:12-07:00
by vav
Sure, here it is:

Code: Select all

convert -background none -pointsize 300 -font trikotnr1.ttf label:7 7.png

Code: Select all

<?php
$mgck_wnd = NewMagickWand();
$drw_wnd = NewDrawingWand();

DrawSetFont($drw_wnd, 'trikotnr1.ttf');
DrawSetFontSize($drw_wnd, 300);
list( , , $text_ascent, $text_descent, $text_width, $text_height, $max_horizontal_advance) = MagickQueryFontMetrics($mgck_wnd, $drw_wnd, '7');

MagickNewImage($mgck_wnd, $text_width, $text_height, 'none');
MagickAnnotateImage($mgck_wnd, $drw_wnd, 0, $text_height + $text_descent, 0, '7');

MagickSetImageFormat($mgck_wnd, 'png');
MagickWriteImage($mgck_wnd, 'test.png');

DestroyDrawingWand($drw_wnd);
DestroyMagickWand($mgck_wnd);
?>

Posted: 2007-01-25T10:01:37-07:00
by magick
Substitute this code:
  • MagickNewImage($mgck_wnd, $text_width, $text_ascent - $text_descent'none');
    MagickAnnotateImage($mgck_wnd, $drw_wnd, 0, $text_ascent, 0, '7');