note 101027 added to function.imagick-queryfontmetrics
| From: | george at sogetthis dot com | Date: | Sun, 21 Nov 2010 23:44:17 +0000 |
| Subject: | note 101027 added to function.imagick-queryfontmetrics | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174238@lists.php.net to get a copy of this message | ||
Up to and including imagick 3.0.1, queryfontmetrics would output size data based on an image
resolution of 72x72. (see bug: http://pecl.php.net/bugs/bug.php?id=19907)
Should you have set a resolution other than this and be using 3.0.1 or below, you need to scale
measurements up by a factor of YOUR_RESOLUTION / 72
e.g. assuming you've set a resolution of 300
<?php
$im = new Imagick();
$im->setResolution(300,300);
$draw = new ImagickDraw();
$draw->setFont('/path/to/arial.ttf');
$draw->setFontSize(72 * (300 / 72));
$data = $im->queryfontmetrics($draw, 'hello world');
var_dump($data);
?>
In 3.0.2 and above, the solution is to set the resolution on the draw object to that of the image
resolution
<?php
$im = new Imagick();
$im->setResolution(300,300);
$draw = new ImagickDraw();
$draw->setResolution(300,300);
$draw->setFont('/path/to/arial.ttf');
$draw->setFontSize(72);
$draw->setFillColor('#ff0000');
$data = $im->queryFontMetrics($draw, $string);
var_dump($data);
?>
----
Server IP: 87.124.126.137
Probable Submitter: 95.150.178.175 (proxied: 95.150.178.175)
----
Manual Page -- http://www.php.net/manual/en/function.imagick-queryfontmetrics.php
Edit -- https://master.php.net/note/edit/101027
Del: integrated -- https://master.php.net/note/delete/101027/integrated
Del: useless -- https://master.php.net/note/delete/101027/useless
Del: bad code -- https://master.php.net/note/delete/101027/bad+code
Del: spam -- https://master.php.net/note/delete/101027/spam
Del: non-english -- https://master.php.net/note/delete/101027/non-english
Del: in docs -- https://master.php.net/note/delete/101027/in+docs
Del: other reasons-- https://master.php.net/note/delete/101027
Reject -- https://master.php.net/note/reject/101027
Search -- https://master.php.net/manage/user-notes.php