MagickQueryFontMetrics() differs from command line

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
vav

MagickQueryFontMetrics() differs from command line

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post 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.
vav

Post 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);
?>
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post 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');
Post Reply