php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17151 ImageTTF* has stopped working
Submitted: 2002-05-11 00:31 UTC Modified: 2002-07-07 01:00 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: nick at asknick dot com Assigned:
Status: No Feedback Package: GD related
PHP Version: 4.1.2 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nick at asknick dot com
New email:
PHP Version: OS:

 

 [2002-05-11 00:31 UTC] nick at asknick dot com
ImageTTF* has stopped working the way it used to. I have sideways text on my site, and it worked great under earlier versions of PHP (for an example, please see http://AskNick.com, running under 4.0.6). Now, under >=4.1.2, specifying any angle for the text other than 0 results in a broken link (see http://SoundBytes.org - same code, running under 4.1.2). Same code running under 4.2.0 can be seen on http://sbarch.cob.rit.edu, but there I used a 45-degree angle, which I think illustrates the problem handily - each letter of the text is at an incorrect 90 degrees, althought the angle of the text itself is the correct 45 degrees. Had I used a 90-degree angle, then the letters would have been individually upside down, but the text would have been correctly vertical. Also, kerning between letters is way off at 90.

Here is the code I'm using on all three sites:

<?PHP 
 header("Content-Type: image/gif");
	// GRAFTEXT
	// takes:
	// $title - the text of the title
	// $titlecolor - the color of the title
	// $titlefont - the font for the title
	// $titlesize - font size of the title
	// $rotation - the angle of the title - 0 = normal; 90 = straight up
	// background will be transparent

// THIS FUNCTION UNHEXIZES A COLOR
	function unhexize ($color) { 
		$color = hexdec($color); 
		$red = ($color&0xFF0000)>>16; 
		$green = ($color&0xFF00)>>8; 
		$blue = ($color&0xFF); 
		return array ($red, $green, $blue); 
	} 

// determine font height.
	$bbox = ImageTTFBBox($titlesize, $rotation, $titlefont, "W");
	if ($rotation < 0) {
	 $font_height = abs($bbox[7]-$bbox[1]);  
	} else if ($rotation > 0) {
		$font_height = abs($bbox[1]-$bbox[7]);
		} else {
			$font_height = abs($bbox[7]-$bbox[1]);
			}

// determine bounding box.
	$bbox = ImageTTFBBox($titlesize, $rotation, $titlefont, $title);
		if ($rotation < 0) {
		  $width = abs($bbox[4]-$bbox[0]);
		  $height = abs($bbox[3]-$bbox[7]);
		  $offset_y = $font_height;
		  $offset_x = 0;
  
	 } else if ($rotation > 0) {
		  $width = abs($bbox[2]-$bbox[6]);
		  $height = abs($bbox[1]-$bbox[5]);
		  $offset_y = abs($bbox[7]-$bbox[5])+$font_height;
		  $offset_x = abs($bbox[0]-$bbox[6]);
  
		} else {
		  $width = abs($bbox[4]-$bbox[6]);
		  $height = abs($bbox[7]-$bbox[1]);
		  $offset_y = $font_height;
		  $offset_x = 0;
			}

	$bgc = unhexize($titlecolor);

	$im = ImageCreate($width+3,$height+3);

	$backcolor = ImageColorAllocate($im, 255, 255, 255);
	$trans = ImageColorTransparent($im, $backcolor);
	$titlecolor = ImageColorAllocate($im, $bgc[0], $bgc[1], $bgc[2]);
	$white = ImageColorAllocate($im, 255, 255, 255);
	$green = ImageColorAllocate($im, 0, 191, 0);
	$brown = ImageColorAllocate($im, 128, 0, 0);
	$blue = ImageColorAllocate($im, 0, 0, 255);

	ImageTTFText($im, $titlesize, $rotation, $offset_x, $offset_y, $titlecolor, $titlefont, $title);

	ImagePNG($im);
	ImageDestroy($im);
?>

You call it with:

<?PHP 
	$title = "TextGoesHere";
	echo "<IMG SRC=\"/includes/graftext.php?title=$title&titlecolor=$titlecolor&titlefont=$titlefont&titlesize=$titlesize&rotation=$rotation\" ALT=\"$title\">";
?>

Thanks for any light you can shed on this problem!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-12 09:33 UTC] rasmus@php.net
PHP doesn't implement any of these low-level functions.  They are implemented by the GD and Freetype libraries.  Did you change/upgrade either of these?
 [2002-05-15 01:11 UTC] Nick at asknick dot com
I'll check and let you know - thanks!
 [2002-06-06 21:56 UTC] nick at asknick dot com
Upgrading to the latest FreeType fixed the problem. Thanks, and sorry for thinking it was PHP!
 [2002-06-06 22:15 UTC] mfischer@php.net
Can you, for the record, please tell us which freetype version you've used before and after then set the status to closed? thx
 [2002-07-07 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2002-07-09 17:56 UTC] dpetrov at nchcapital dot com
Apparently, $size and $text are undefined. To understand the 
reason, check this place:

http://www.php.net/manual/en/language.variables.predefined.php

Because of that, $xsize and $ysize gets equal to 10, and you end 
up generating blank 10x10 PNG image.

Try to add this at the beginning of your script (before $box =):

$size = $_GET['size'];
$text = $_GET['text'];

Hope it helps.
 [2002-07-09 17:57 UTC] dpetrov at nchcapital dot com
oops... please disregard my comment - it was supposed to go to a different plase...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 15:01:32 2024 UTC