Error: Allowed memory size exhausted
Posted: Tue Sep 04, 2007 10:57 am
feyd | Please use
...while trying to run a utility script whose purpose is to use GDLib version 2.0.28 compatible with PHP version 4.3.10 to create (a) a thumbnail image and (b) a "normal-sized" image for each uploaded JPEG in a staging directory on the (LINUX) server.
One function populates an array with the file names of all images in the staging directory and then calls another function to create and store the images (in other directories).
In my testing, I'm using only 3 JPEGs, each between 385KB and 575KB.
When I invoke only the call for the thumbnails (fixed width of 120px; height calculated), things work. It's when I call the function for the normal images with a target width greater than 365px (even if I've commented out and bypassed the call for the thumbs), I get the above message (where the numbers of bytes in the "tried to allocate" part are multiples of the target width (?)). (Ideally, I want the target width of normal images to be 600px.)
Here are pertinent code snippets:
The loop:
The called function:
Any insights?
Thank you in advance
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am encountering the following error message...Code: Select all
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 600 bytes) in [path/]functions.php on line 219One function populates an array with the file names of all images in the staging directory and then calls another function to create and store the images (in other directories).
In my testing, I'm using only 3 JPEGs, each between 385KB and 575KB.
When I invoke only the call for the thumbnails (fixed width of 120px; height calculated), things work. It's when I call the function for the normal images with a target width greater than 365px (even if I've commented out and bypassed the call for the thumbs), I get the above message (where the numbers of bytes in the "tried to allocate" part are multiples of the target width (?)). (Ideally, I want the target width of normal images to be 600px.)
Here are pertinent code snippets:
The loop:
Code: Select all
for ( $f=0; $f<count($file_listing); $f++ )
{
$filename = GALLERY_IMAGES_SOURCE_DIR . $file_listing[$f];
make_images_step2($filename, DEST_DIR_THUMB, WIDTH_THUMB, QUALITY_THUMB);
make_images_step2($filename, DEST_DIR_NORMAL, WIDTH_NORMAL, QUALITY_NORMAL);
}Code: Select all
function make_images_step2($filename, $where, $width, $quality)
{
// - Create and move the images
$fx = basename($filename); // just the file and extension 9/3/2007
$source = imagecreatefromjpeg($filename);
$thumbX = $width;
$imageX = imagesx($source);
$imageY = imagesy($source);
$thumbY = (int)(($thumbX*$imageY) / $imageX );
$dest = imagecreatetruecolor($thumbX, $thumbY);
imagecopyresampled ($dest, $source, 0, 0, 0, 0, $thumbX, $thumbY, $imageX, $imageY);
// 9/3/2007: Write the file here!
imagejpeg($dest, $where . $fx, $quality);
imagedestroy($dest);
imagedestroy($source);
} // End functionThank you in advance
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]