Hi, I'm putting the finishing touches on an image upload script. I have the image uploading successfully but now I wish to create a thumbnail from it. I have the following function setup:
The function is contained within a class where the path is set. The path and file name is the same I use to do the upload so I don't know it should not be working. Here's the error message I'm getting:
Warning: getimagesize(Resource id #18) [function.getimagesize]: failed to open stream: No such file or directory in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 119
Warning: Division by zero in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 124
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 127
Notice: Use of undefined constant width - assumed 'width' in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 128
Notice: Use of undefined constant height - assumed 'height' in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 128
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 128
Warning: imagejpeg(): supplied argument is not a valid Image resource in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 129
I would appreciate it if someone could help. Thanks
btw I definately have the gd2 library turned on (I check with the phpinfo() function).
Code:
function upload_thumbnail($file_name, $thumbnail_width, $thumbnail_height) {
$image = imagecreatefromjpeg($this->path . $file_name);
echo $this->path . $file_name;
list($width, $height) = getimagesize($image);
if ($width < $height) {
$thumbnail_width = ($thumbnail_height / $height) * $width;
} else {
$thumbnail_height = ($thumbnail_width / $width) * $height;
}
$thumbnail = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, width, height);
imagejpeg($thumbnail, $this->path . 'thumbnails/' . $file_name, 100);
return true;
}
The function is contained within a class where the path is set. The path and file name is the same I use to do the upload so I don't know it should not be working. Here's the error message I'm getting:
Warning: getimagesize(Resource id #18) [function.getimagesize]: failed to open stream: No such file or directory in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 119
Warning: Division by zero in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 124
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 127
Notice: Use of undefined constant width - assumed 'width' in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 128
Notice: Use of undefined constant height - assumed 'height' in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 128
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 128
Warning: imagejpeg(): supplied argument is not a valid Image resource in U:\My Webs\Site\Scripts\CMS\includes\upload.inc.php on line 129
I would appreciate it if someone could help. Thanks
btw I definately have the gd2 library turned on (I check with the phpinfo() function).