php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59509 queryfontmetrics not respecting setresolution
Submitted: 2010-11-15 05:29 UTC Modified: 2010-11-21 06:58 UTC
From: george at sogetthis dot com Assigned:
Status: Closed Package: imagick (PECL)
PHP Version: 5.3.2 OS: -
Private report: No CVE-ID:
 [2010-11-15 05:29 UTC] george at sogetthis dot com
Description:
------------
If $im->SetResolution is used to set a resolution, queryfontmetrics doesn't respect the value. Changing the $print_resolution in the reproduce code doesn't affect the queryfontmetrics textWidth measurement, whereas the actual image dimension as calculated by drawImage'ing the data does.

Also, is the input to queryfontmetric point size or pixel height?

Reproduce code:
---------------
<?php
$print_resolution = 300;
$string = "Hello World";
$fontsize = 72;

$im = new Imagick();
$im->setResolution($print_resolution,$print_resolution);
$im->newImage(9040,3400, "white","png");
$im->setImageUnits(1);

$draw = new ImagickDraw();
$draw->setFont('/path/to/arial.ttf');
$draw->setFontSize($fontsize);
$draw->setFillColor('#ff0000');
$data = $im->queryFontMetrics($draw, $string);

// draw image to test actual height
$draw->annotation(0, $data['ascender'] * ($print_resolution / 72), $string);
$im->drawImage($draw);
$im->trimImage(0);
//header('content-type:image/png');
//die($im);

$dataii = $im->identifyimage();
print ":identifyimage height:" . $dataii['geometry']['height'];
print "<br/>-----------------------------<br/>";
print ":queryfontmetrics height: " . $data['textHeight'];


Expected result:
----------------
changing the $print_resolution gives different values from identifyimage, but the output to queryfontmetrics does not change.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-20 09:00 UTC] wizard at imagemagick dot org
Imagick is missing a method to set the drawing / annotation resolution. $im->setResolution() set the image resolution. Imagick needs a $draw->setResolution() method that sets the draw_info->density member. Since density is a string, you simply take the setResolution() float values and convert them to a string and assign it to the density member of the DrawInfo structure.
 [2010-11-20 20:37 UTC] george at sogetthis dot com
it looks like the api doesn't have a method to set the drawing / annotation density?
 [2010-11-21 06:38 UTC] mkoppanen@php.net
Seems like the PeekDrawingWand returns a copy of the DrawInfo structure. Currently the only way I can see is using PeekDrawingWand and allocating a new DrawingWand using DrawAllocateWand and the given draw_info.
 [2010-11-21 06:58 UTC] mkoppanen@php.net
This bug has been fixed in SVN.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 16 21:02:09 2014 UTC