Page 1 of 1

imagedestroy problem

Posted: Mon Jan 05, 2009 2:31 am
by rc726c
could someone tell me, whats wrong with this code at below??
it gets an error_log like this:
[Wed Dec 10 02:58:05 2008] [error] [client 195.xxx.xx.32] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /var/www/html/w/htdocs/online/duckula/fotolar/thumb.php on line 47, referer: http://www.site.com/

<?

/*
===================================
+ yThumb Class
+ Author: Yunus Emre Yilmaz
+ http://yns.zaxaz.com/ythumb.yns
===================================
*/

class yThumb {

// find extension of file
function find_extension($file) {
$array = explode('.',$file);
$key = count($array) -1;
$ext = $array[$key];
return $ext;
}

function thumb($image,$w,$h) {
if($this->find_extension($image) == 'jpg') $image_data = imagecreatefromjpeg($image);
if($this->find_extension($image) == 'gif') $image_data = imagecreatefromgif ($image);
if($this->find_extension($image) == 'png') $image_data = imagecreatefrompng ($image);

// Original width && height
$width = imagesx($image_data);
$height = imagesy($image_data);

// Control width && and height
if(@$w > 800 || @$h > 800) {
$w= $width; $h= $height;
}

if(@empty($w)) $w = 400;
if(@empty($h)) $h = 600;

$new = imagecreatetruecolor($w, $h);
imagecopyresampled($new, $image_data, 0, 0, 0, 0, $w, $h, $width, $height);


// Finally, output..
if($this->find_extension($image) == 'jpg') $image_data = imagejpeg($new);
if($this->find_extension($image) == 'gif') $image_data = imagegif ($new);
if($this->find_extension($image) == 'png') $image_data = imagepng ($new);

// Flush memory
imagedestroy($image_data); // line 47
imagedestroy($new);
}

}

$a = new yThumb();
$a->thumb($_GET["image"],@$_GET["w"],@$_GET["h"]);


?>