Yesterday I logged a bug about the queryfontmetrics() function not
having been implemented. And today--thanks to Vito, one of the lead
developers--it's been done and checked into the SVN repository:
http://svn.php.net/viewvc/pecl/gmagick/trunk/
So if you check out the latest version and build it, you can now do
something like this:
$gm = new Gmagick('/path/to/file.jpg');
$wand = new GMagickDraw();
$wand->setfont("Impact")
->setFontSize(50)
->setStrokeColor('black')
->setStrokeWidth(1)
->setStrokeOpacity(0.8)
->setFillColor('white');
$metrics = $wand->queryfontmetrics($gm,'This is a test.');
And $metrics will contain an array that looks like this:
Array
(
[characterWidth] => 50
[characterHeight] => 50
[ascender] => 51
[descender] => -11
[textWidth] => 261
[textHeight] => 61
[maximumHorizontalAdvance] => 64
)
textWidth and textHeight describe the pixel size of the to-be-rendered
text.
Neat!