Click to See Complete Forum and Search --> : Undefined function
Cactus Hugger
03-27-2003, 03:07 PM
PHP is outputtin that the imagecreatefromgif() and png is undefined. I have PHP 4.3.0 for Windows... here's the line in error:
$ThePic = imagecreatefrompng($PicFile);
But, I don't understand why it should be undefined... I have the latest version of PHP and the gd.dll (Or something close to that... at school so I can't check.)
:o This is really pissing me off... Thanks In Advance for any and all help.
jpmoriarty
03-27-2003, 03:22 PM
it's missing the gd library i'm afraid - you'll need to check php.ini to make sure it's enabled. and for php help i'd suggest heading over to the php builder board (http://www.phpbuilder.com/board)
Cactus Hugger
03-27-2003, 06:40 PM
Thanks for your reply. I have corrected the php.ini file, and no longer get errors. However, execution stops after calling imagecreatefromgif();
$PlayerPic = imagecreatefromgif($PicFile);
echo "TEST";
$PicFile = A picture that is in the same dir as the script. Such as mypic.gif. (This has been checked, the var has the right value.)
However, TEST is never echoed
jpmoriarty
03-28-2003, 03:26 AM
no no no no no that's not how it works. You cant just call a function like that and it will display an image - think about it in terms of the PHP creating html - you need an <img src=...> tag to get an image, and that's not what that function creates.
What you need to do is create a makeimage.php file (i've posted the one i use for jpegs just for you to look at) and then call it from your main php file like so:
echo "<img src=\"makeimage.php?directory=1&file=this.jpg\">
here's my makeimage.php file:
<?
// if (!$max_width)
$max_width = 100;
// if (!$max_height)
$max_height = 100;
$file = $directory."/".$file;
$size = GetImageSize($file);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = ImageCreateFromJpeg($file);
$dst = ImageCreate($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
$tn_width,$tn_height,$width,$height);
header("Content-type: image/jpeg");
ImageJpeg ($dst, '', 90);
ImageDestroy($src);
ImageDestroy($dst);
?>
given as your code is generating an image, putting things like echo into it dont do anything or will confuse it - they'll have to go in your main script.
Cactus Hugger
03-28-2003, 09:46 PM
Thanks so much. I now understand this a whole lot better. I put the image function in it's own file. Now it creates a 32x32 picture, and works almost perfectly. One problem:
echo "<img src=\"findPlayerpic.php?PicNum=".$ThePicNum."\">";
The actual file:
<HTML>
<?php
echo $PicNum;
// Just testing that var for now...
?>
$PicNum is null. Why? How can I retrieve it from the URL?
jpmoriarty
03-29-2003, 06:39 AM
you dont (correctly) have globals on - use $_GET['variable name'] to get to the URL variables:
echo "<img src=\"findPlayerpic.php?PicNum=$ThePicNum\">";
then:
echo $_GET['PicNum']