I have a family website where pics are uploaded by endusers and cataloged in a db table. The index page randomly picks a pic and displays it. I have been setting the width to be a standard 200 in the img tag. I am looking to autothumbnail the pics so that I do not have to wait for the HUGE pics to download when I really only want a small pic there (they can then click on the thumbnail to view the full size pic)
I have found a few scripts that work but I seem to be having a problem with the size of some of the pics.
I am getting the following error:
Fatal error: Allowed memory size of 18388608 bytes exhausted (tried to allocate 10320 bytes) in thumbnail.php on line 18
I believe that it is stemmed from the imagecreatefromjpeg() function. Is there a way around the size limitation?
Listed below is my entire thumbnail script just in case I am looking in the wrong place.
<?php
$pic="pic/Lincoln2.jpg";
function imagecopyresampledselection($filename, $desired_width, $desired_height, $bordersize, $position)
{
// Get new dimensions
list($width, $height) = getimagesize($filename);
if($desired_width/$desired_height > $width/$height):
$new_width = $desired_width;
$new_height = $height * ($desired_width / $width);
else:
$new_width = $width * ($desired_height / $height);
$new_height = $desired_height;
endif;
// Resize
$image_p = imagecreatetruecolor($new_width, $new_height);
$image_f = imagecreatetruecolor($desired_width, $desired_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Adjust position
switch($position)
{
case("topleft"):
$x = $bordersize;
$y = $bordersize;
break;
case("topright"):
$x = $new_width - $desired_width + $bordersize;
$y = $bordersize;
break;
case("bottomleft"):
$x = $bordersize;
$y = $new_height - $desired_height + $bordersize;
break;
case("bottomright"):
$x = $new_width - $desired_width + $bordersize;
$y = $new_height - $desired_height + $bordersize;
break;
case("center"):
$x = ($new_width - $desired_width) / 2 + $bordersize;
$y = ($new_height - $desired_height) / 2 + $bordersize;
break;
}
// Resample with 1px border
imagecopyresampled($image_f, $image_p, $bordersize, $bordersize, $x, $y, $desired_width - 2 * $bordersize,
$desired_height - 2 * $bordersize,
$desired_width - 2 * $bordersize,
$desired_height - 2 * $bordersize);
return $image_f;
}
$image_f = imagecopyresampledselection($pic, 200, 200, 1, "center");
header('Content-type: image/jpeg');
imagejpeg($image_f, null, 100);
?>
Again... Thank you for any help you may provide....