imagettfbbox() problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

imagettfbbox() problem

Post by vigge89 »

When running this script on my hosts server;

Code: Select all

<?php
//Text to print
$txt = @$_GET['txt'];
if(empty($txt)) { $txt = "vigge89"; };

//Font settings
$font = "HOOG0550.ttf";
$fsize = "6";

$h = 7;	//Height

//Center
$text_bbox = ImageTTFBBox ($fsize, 0, $font, $txt);
$img_width = $text_bbox[2]-$text_bbox[0] + 2 ;

//Create image
$im = imagecreate ($img_width, $h);

//Color setup

$r = @$_GET['r']; // Red
if(empty($r)) { $r = "255"; };
$g = @$_GET['g']; //Green
if(empty($g)) { $g = "255"; };
$b = @$_GET['b']; //Blue
if(empty($b)) { $b = "255"; };

//Set colors
$bc = ImageColorAllocate ($im, 0,0,0); //Background
$fc = ImageColorAllocate ($im, $r,$g,$b); //Text

//Write text from variables
ImageTTFText ($im, $fsize, 0, 1, 6, $fc, $font, $txt);

//Create image
header ("Content-type: image/png");
ImagePNG ($im);
?>
I get the error:
Fatal error: Call to undefined function: imagettfbbox() in C:\Webserver\apache\htdocs\vigge\source\image.php on line 18

GD Library is installed, and also Freetype 2, but what should my host do to make it work?

It works on my local server (ApacheFriends XAMPP for windows Version 1.0), but not on his.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Does GD appear if you do:

Code: Select all

echo '<pre>';
print_r(get_loaded_extensions());
echo '</pre>';
Mac
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

nope, just:
[0] => standard
[1] => bcmath
[2] => calendar
[3] => com
[4] => ftp
[5] => mysql
[6] => odbc
[7] => pcre
[8] => session
[9] => xml
[10] => wddx
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

I succeded in creating my own string-lenght checker :D ;

Code: Select all

<?php
	//Check number of characters
	$img_width = strlen($txt) * 6;

	//Check if there are any special chars
	$numI = substr_count($txt, "i"); //I's
	$numspc = substr_count($txt, "_"); //_'s
	$num1 = substr_count($txt, "1"); //1's
	$numdots = substr_count($txt, "."); //.'s
	$numsep = substr_count($txt, "-"); //-'s

	//If there is, change the lenght of image
	If ($numI > 0) { $img_width = $img_width - ($numI * 2); };
	If ($numspc > 0) { $img_width = $img_width - ($numspc * 3); };
	If ($num1 > 0) { $img_width = $img_width - ($num1 * 3); };
	If ($numdots > 0) { $img_width = $img_width - ($numdots * 2); };
	If ($numsep > 0) { $img_width = $img_width - ($numsep * 4); };
?>
it works great when using pixel fonts, which i am using :)
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

worked great on my local server, but not on my hosts one :(
ImageCreate is undefined :/
Doesn't seem like my host did install GD Lbraray at all :(
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

deleted
Last edited by vigge89 on Tue Nov 11, 2003 8:07 am, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

No, GD is not listed in the loaded extensions so it has not been enabled on your hosts server.

Mac
Post Reply