Image creation with PHP

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
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Image creation with PHP

Post by phice »

While trying to make a basic image, I get the error "Fatal error: Call to undefined function: imagegif() in /home/nncommunity/www/test/image.php on line 32".

My code:

Code: Select all

<?php
header("Content-type: image/gif");
$height = 100;
$width = 200;
$fontsize = 50;
if (!isset($text)) { $text = "Test message!"; }
$image = imagecreate($width, $height);
$red = imagecolorallocate($image, 255, 0, 0);
$blue = imagecolorallocate($image, 0, 0, 255);
$font = "/home/nncommunity/www/test/VERDANA.TTF";
$textwidth = $width;
$textheight;
while (1)
	{
		$box = imageTTFbbox($fontsize, 0, $font, $text);
		$textwidth = abs($box[2]);
		$textbodyheight = (abs($box[7])) - 2;
		if ($textwidth < $width - 20)
			break;
		$fontsize--;
	}
$gifXcenter = (int)($width/2);
$gifYcenter = (int)($height/2);
imageTTFtext($image,
$fontsize,
0,
(int) ($gifXcenter-($textwidth/2)),
(int) ($gifYcenter+(($textbodyheight)/2)),
$blue,
$font,
$text);
imagegif($image);
?>
I've got the font "VERDANA.TTF" uploaded into the correct path, but I still receive the "unknown function" as stated above. Any help?
Image Image
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

your server most likely doesn't have the imagegif function. newer releases of GD don't, as Unisys owns the copyright to the gif compression, or something like that. you could try png, however a lot of older browsers don't support that image type.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

yeah, gif support was dumped which i am very sore about. id would much like to use it to make thumbnails in a future image gallery.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

imagepng() works perfectly. ;]
Image Image
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Is anything wrong with imagejpeg?
Post Reply