Page 1 of 1
Image uploader
Posted: Fri Oct 16, 2009 4:30 pm
by Da_Elf
Ive created an image uploader which ive used on a few sites. its rather simple. however i was testing with a semi large image and got an error.
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 9088 bytes)
the file size is 870kb and the file uploads to the server. i can see it there. however my uploader resizes the jpgs as well and the fatal error is in the area here on the 2nd line listed
Code: Select all
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
how do i allocate more memory if thats whats needed
Re: Image uploader
Posted: Fri Oct 16, 2009 4:37 pm
by Mark Baker
Resizing an image using gd is notoriously memory intensive, your only real solution is to increase the memory limit for your scripts in php.ini
Re: Image uploader
Posted: Fri Oct 16, 2009 5:24 pm
by Da_Elf
it seems my php.ini file says 32MB. why would it max out at 32mb when the original file isnt even 1mb
Re: Image uploader
Posted: Sat Oct 17, 2009 3:55 am
by Mark Baker
Da_Elf wrote:it seems my php.ini file says 32MB. why would it max out at 32mb when the original file isnt even 1mb
You'd have to look at the innards of the GD library to get an answer to that.
Your file might seem small, but most image files use compression.... it needs to be decompressed before it can be manipulated (e.g. for thumbnailing)
Somebody might actually
know the answer, I can only
surmise: but I'd suspect that it's taking your original image and converting it to a bitmap internally. Then, if your original image was 320x200 pixels, it would require 256k or memory (4 bytes/pixel) just to hold it in memory. Resizing would require two copies, so 512k. That's just for a small image. 640x480 would take 2.4M.
As I said previously: for whatever reason, any GD image manipulation is know to take large volumes of memory, so you need to make allowance for this when configuring your server to work with large images.
Your alternative, if you don't want to increase PHP memory, is to use external image libraries and call them using exec.
Re: Image uploader
Posted: Sat Mar 13, 2010 7:43 am
by Da_Elf
im getting sick of the GD library with resizing images. i had to increase a the file limit to 50M and a 2.3mb jpg still couldnt be processed by it. what are the other options for resizing images for thumbnails
Re: Image uploader
Posted: Sat Mar 13, 2010 9:04 am
by McInfo
Edit: This post was recovered from search engine cache.