note 74207 added to function.imagefttext
| From: | darren at badpun dot co dot uk | Date: | Thu, 29 Mar 2007 21:58:18 +0000 |
| Subject: | note 74207 added to function.imagefttext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124933@lists.php.net to get a copy of this message | ||
I had trouble working out how to accurately represent fonts in point sizes when constructing charts
that had a user-customisable output DPI (basically, the user could specify the size of the chart in
mm - or any other physical measure - and the DPI to create arbitrarily-sized charts to work properly
in real printed documents).
GD1 was OK as it used pixels for font rendering, but GD2 uses points, which only makes any sense if
you know the DPI that it assumes when rendering text on the image surface. I have not been able to
find this anywhere in this documentation but have examined the GD2 source code and it appears to
assume a DPI of 96 internally. However, this can easily be customised in the GD2 source so it cannot
be assumed that all PHP interpreters out there have a GD2 compiled using 96dpi internally.
If it does, and you are using it to construct images whose target DPI is not 96, you can calculate
the point size to supply to imageftbox() and imagefttext() like this:
<?php
/* 100mm x 100mm image */
$imageWidth = 100;
$imageHeight = 100;
/* 300 dpi image, therefore image is 1181 x 1181 pixels */
$imageDPI = 300;
/* unless we do this, text will be about 3 times too small */
$realFontSize = ($fontPt * $targetDPI) / 96;
?>
----
Server IP: 194.145.210.4
Probable Submitter: 80.5.160.8 (proxied: 82.12.151.83)
----
Manual Page -- http://www.php.net/manual/en/function.imagefttext.php
Edit -- https://master.php.net/note/edit/74207
Del: integrated -- https://master.php.net/note/delete/74207/integrated
Del: useless -- https://master.php.net/note/delete/74207/useless
Del: bad code -- https://master.php.net/note/delete/74207/bad+code
Del: spam -- https://master.php.net/note/delete/74207/spam
Del: non-english -- https://master.php.net/note/delete/74207/non-english
Del: in docs -- https://master.php.net/note/delete/74207/in+docs
Del: other reasons-- https://master.php.net/note/delete/74207
Reject -- https://master.php.net/note/reject/74207
Search -- https://master.php.net/manage/user-notes.php