Re: TrueType font changes size when rotated?
| From: | jekillen | Date: | Wed, 25 Apr 2007 05:29:16 +0000 |
| Subject: | Re: TrueType font changes size when rotated? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-253665@lists.php.net to get a copy of this message | ||
On Apr 24, 2007, at 8:26 PM, Seth Price wrote:
Hi all! I've been programming GD and PHP for a while, but I haven't done much with font drawing. I'm trying to layout and draw text, but the text actually changes size and shape depending on the angle it's drawn at. This is making it extremely difficult to lay the text out properly. Am I doing something wrong? Is there a bug in FreeType? How can I consistently draw text? For example: The following code draws 'Hello world' at differing angles. But all drawings are at right angles to each other. FreeType shouldn't even need to do any resampling or interpolating, but each text is drawn with a unique length and look. You can see the output of the following code here: http://leopold.sage.wisc.edu/test2.php <?php header('Content-Type:image/png'); $img = imagecreatetruecolor(300, 300); $bak = imagecolorexact($img, 255,255,255); imagefill($img, 0,0, $bak); $col = imagecolorexact($img, 0,0,0); for($i = 0; $i < 360; $i += 90){ $b = imageftbbox(12, $i, '/Library/WebServer/Verdana.ttf', 'Hello world'); $len = sqrt(($b[2] - $b[0])*($b[2] - $b[0]) + ($b[3] - $b[1])*(($b [3] - $b[1]))); imagefttext($img, 12, $i, 150, 150, $col, '/Library/WebServer/ you're using Mac OSX, did you have to install gd or does it now come withgd included in the php installation? (after looking further down the message, I see you are running Server, so that is probably the difference) Mine did not (OSX 1.4x). I have it installed on a FreeBSD system. www.brushandbard.com -> web design -> dynamic image generation demonstration and Word Wise the Tile Puzzle are some of my projects using gd.
Verdana.ttf', 'Hello world '.$len); } imagepng($img); ?> When using more interesting fonts, this 'resampling' is causing text drawn at 90 deg to look fugly. What can I do to prevent this? Is this a known issue? The output doesn't seem to change if I use the 'ttf' functions vs. the 'ft' functions. I went looking for some samples, as I have played with this some in thepast, but did not find anything current to show. I do not remember having this problem. There may be a distortion that is being entered into the mix when the fonts are rendered by your code. $len is the hypoteneus of a right triangle, right off hand I would say that is your problem or some of it. The length should be a linear measurement and not a diagonal measurement. But I am rusty at this point. Also there is a function for explicitly specifying the angle of the font in degrees, and, as I remember the angle of the rendering box also. This is so each font can be rendered at an individual angle and the whole enclosing box, so the whole word is rotated. you will have to look in the manual for gd related functions if you are not aware of this. Jeff K
System info: Mac v10.4 Server running PHP v5.2.1 & FreeType v2.3.4 Compiled with: './configure' '--with-apxs' '--with-mysqli=/usr/local/mysql/bin/ mysql_config' '--with-gd' '--with-png-dir=/usr/local' '--with-zlib- dir=/usr' '--with-jpeg-dir=/usr/local' '--disable-short-tags' '--with- iconv' '--enable-exif' '--enable-mbstring' '--enable-gd-native-ttf' '--with-freetype-dir=/usr/local' Thanks, Seth -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php