Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
11-18-2007, 01:30 PM #1
- Join Date
- Feb 2007
- Thanked 0 Times in 0 Posts
imagecreatefromjpeg() using far too much memory for what is needed
I am creating a website for a friend of mine who is a model.
One of the things that she would like for the website to do, is to allow her to choose a file that she wants on the website and then for using a simple form on the website to upload the file and then make a thumbnail of that picture.
The code I am using for the creation of the thumbnail is...
function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbHeight)
$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
$origWidth = imagesx($srcImg);
$origHeight = imagesy($srcImg);
$ratio = $origHeight / $thumbHeight;
$thumbWidth = $origWidth / $ratio;
imagejpeg($dst_img,$thumbDirectory . "/" . $imageName);
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 9792 bytes) in /home/fhlinux159/s/sarah.satalketo.co.uk/user/htdocs/adminPhotos.php on line 5
Now considering the original file was 426KB I think it using up 32MB is a little silly.
So I was wondering whether I have made an error somewhere and this is causing the massive usage of memory.
11-18-2007, 04:24 PM #2
- Join Date
- Oct 2006
- Denver, Colorado USA
- Thanked 333 Times in 325 Posts
Jpg/jpeg/gif/png images are compressed. To be able to operate on the images and do things like add text, draw on them, crop, rotate, save or output them in other formats the GD imagecreate.... functions uncompress the image data into a bitmap image.
From the GD section of the manual -The total memory used is everything your program consumes for php code and data. If your code is looping over a number of images or has a lot of resources allocated for arrays or database result sets, you can probably free up some memory. Otherwise, you will need to increase the amount of memory available to php - see the memory_limit setting.Warning
Image functions are very memory intensive. Be sure to set memory_limit high enough.
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.