[SOLVED] Not enough memory for imagecreatefromjpeg()
Posted: Thu Dec 15, 2005 8:04 am
I'm trying to create a feature for a client's CMS that will allow them to upload 3 images straight off a digital camera, have them resized 3 different ways (thumbnail, large, and one specifically to go in a PDF) and I wrote a script that did that fine, plus created a pdf. The script ran sucessfully both locally and on the server.
The trouble was I was just uploading various jpegs I had scattered about my machine. The photos I was experimenting with came off my really old 2megapix Canon Ixus V and were all <300k and 1024x768.
It then occured to me that newer digicams produce much larger images and uploading 3 at a time would possibly exceed the max upload limit on our hosts PHP configuration, so I rewrote the script to handle one image at a time, and got a few images to test with from my boss's slightly newer camera which were 1600 x 1200 and 655kb.
Everytime I uploaded the image the script went to a file not found error after a long struggle. Since the page was submitting to itself this seems ridiulous. I would have expected a timeout error perhaps.
So I made a test script to upload the image, and make a smaller copy from it, then display it in the browser.
Each time I get the following error:
Line ten was where imagecreatefromjpeg() was called.
The entire script is as follows:
I don't honestly think this has anything to do with my problem but in the manual for imagecreatefromjpeg someone claims that images from a Canon PowerShot S70 causes PHP to crash with a page canot be displayed error. The image I am using came from a Powershot A40.
Someone please tell me that I've just written a poor script and show me how to fix it!
The trouble was I was just uploading various jpegs I had scattered about my machine. The photos I was experimenting with came off my really old 2megapix Canon Ixus V and were all <300k and 1024x768.
It then occured to me that newer digicams produce much larger images and uploading 3 at a time would possibly exceed the max upload limit on our hosts PHP configuration, so I rewrote the script to handle one image at a time, and got a few images to test with from my boss's slightly newer camera which were 1600 x 1200 and 655kb.
Everytime I uploaded the image the script went to a file not found error after a long struggle. Since the page was submitting to itself this seems ridiulous. I would have expected a timeout error perhaps.
So I made a test script to upload the image, and make a smaller copy from it, then display it in the browser.
Each time I get the following error:
Code: Select all
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 4800 bytes) in /home/fhlinux202/i/ib3.co.uk/user/htdocs/alltask/admin/test.php on line 10The entire script is as follows:
Code: Select all
$imagetmp = $_FILES['pic1']['tmp_name'];
$new_width = 150;
list($width, $height, $type, $attr) = getimagesize($imagetmp);
$tempImage = imagecreatefromjpeg($imagetmp);
$new_height = round($height/($width/$new_width));
// Resample
$newImage = imagecreateTrueColor($new_width, $new_height)
or die("<B>Error: New image could not be created.</B> ");
// Do a bicubic resample
imagecopyresampled($newImage, $tempImage, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
header("Content-type: image/jpeg");
imagejpeg($newImage);Someone please tell me that I've just written a poor script and show me how to fix it!