php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15656 text is rendered too large
Submitted: 2002-02-21 05:40 UTC Modified: 2002-08-10 07:35 UTC
From: weber at capcom dot de Assigned:
Status: Closed Package: GD related
PHP Version: 4.0.6 OS: SuSE 7.0/kernel 2.2.16
Private report: No CVE-ID: None
 [2002-02-21 05:40 UTC] weber at capcom dot de
<?
$im = imageCreate(170,136);
ImageColorAllocate ($im, 128,128,150);
$black = ImageColorAllocate ($im, 0, 0, 0);
ImageTTFText($im, 18, 0, 17, 40, $black, "./verdana.ttf", "HELLO WORLD");
ImageGif ($im);
?>

'./configure' '--prefix=/home/weber' '--with-png-dir=/home/weber' '--with-apxs=/home/weber/bin/apxs' '--with-zlib' '--with-gd=/home/weber' '--enable-gd-native-tt' '--with-ttf=/home/weber' '--with-gettext' '--with-mysql' '--enable-sockets' '--with-zlib-dir=/usr' '--with-bz2'

gd version 1.8.4 & 1.8.3(tested both)
freetype version 1.3.1

Would be nice to have this annoying bug solved.......

Webster

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-28 04:13 UTC] sniper@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately your version of PHP is too old -- the problem
might already be fixed. Please download a new PHP
version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 [2002-07-01 12:09 UTC] markonen@php.net
PHP's gd interface currently uses an output resolution of 
72dpi. This means that a letterform 72 points (= one inch) 
high will result in output that is 72 pixels high.

If you are used to some other dpi setting, the text gd 
outputs may appear either too big or too small. 
Compensating for this is luckily very easy.
 [2002-08-10 06:09 UTC] php at tecnopolis dot ca
> Compensating for this is luckily very easy.

But you fail to say how?  Another Fermat?

I've tried simply manually scaling down the font size, but I can't get ttf's in php 4.1.2 to look the same as they did in 4.0.6 (which looked nice!)

Please fill us in!  Thanks.
 [2002-08-10 07:33 UTC] wez@php.net
IIRC, GD changed from using pixel size for fonts to using
point size.  That explains the difference in size.
Fortunately, it is easy to compensate:

1 point = 1/72 of an inch.
10 points using a 96 dpi screen = 10/72*96 = 13.3 pixels.

So, to correct the size, divide the size you are passing
into the functions by 1.3 (96/72).
 [2002-08-10 07:35 UTC] markonen@php.net
Well, if you specify a font size of 18 points, how tall, in pixels, is the character 'M' in your output? And how high do you want it to be?
 [2002-12-15 12:39 UTC] thierry at skynet dot be
The fact that GD changed from using pixel size to point size shouldn't matter a lot since we render mostly screen images at 72 dpi and there are 72 points in an inch (72,... but it's generally rounded to 72 per inch). This means that in fact we were used to having for example a 10 point size text rendered to 10 pixels.

Now in comes GD 2, there we have in gd.h
/* resolution affects ttf font rendering, particularly hinting */
#define GD_RESOLUTION           96      /* pixels per inch */

So this means that for font rendering in GD uses 96 dpi. This means that if you use this like we used to (1 point == 1 pixel) GD 2 will have 1 point == 1 pixel/72 * 96, giving 1,333 pixel per point, rendering our beautifull charts in GD 1.x into ugly ones because all the text is too large now...

It took me a while before I found this out (several months of passive searching and since I thought Freetype was at the cause I was looking in the wrong direction...)

Now The case is that this thing comes close to a religious thing (Windows PCs use 96 dpi screen resolution, Macs were like using the 72 dpi resolution), fact is that this is still very noticable in my enviroment. I received marked up email from PC/Windows users that is simply to small to read, Word (office in general) documents from a PC that are sent to me are at 75% zoom out, making the text illegible on the mac, so I need to change the zoom factor every time... Verry funny that in this day and age there is such a difference in the very hart of these systems, that they will never be the same :))

Ok, now for the solution, either change the #define in gd.h or use font sizes of for example 10/96*72 (for a 10 pixel font size).

If you use a lot of small text on the images I recon changing the #define is better that entering fractional sizes....
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC