I get the following error when trying to create a thumbnail of an image:
Warning: imagecopyresized() [function.imagecopyresized]: Invalid image dimensions in H:\Programs\webserver\root\media\images\inc\func.php on line 160
This is the function I have created to do the job:
function create_thumbnail($image_type, $image_height, $image_height, $temp_dir, $thumb_path, $thumb_width, $thumb_height){
switch($image_type){
case 'image/jpeg';
$img = imagecreatefromjpeg($temp_dir);
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresized($thumb, $img, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height);
imagejpeg($thumb, $thumb_path, 100);
break;
case 'image/png';
$img = imagecreatefrompng($temp_dir);
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresized($thumb, $img, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height );
imagepng($thumb, $thumb_path, 100);
break;
case 'image/gif';
$img = imagecreatefromgif($temp_dir);
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresized($thumb, $img, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height );
imagegif($thumb, $thumb_path, 100);
break;
}
}
Which is used like so:
// Create the new thumbnail dimensions
list($thumb_width, $thumb_height) = thumb_dimensions($case, $image_width, $image_height);
// Create the thumbnails
create_thumbnail($image_type, $image_height, $image_height, $temp_dir, $thumb_path, $thumb_width, $thumb_height);
The thumb dimensions are width: 100px, height: 99px;
Typo in the function definition:
which means
$image_widthisn’t defined and will probably evaluate to 0.Same goes for your sample
create_thumbnail()call at the end – two image_heights, no image_width.