Click to See Complete Forum and Search --> : ImageCreateFromJPEG() - Allowed memory exhausted... (problem with dimensions)


mago
02-22-2008, 01:42 PM
When using ImageCreateFromJPEG (e.g. if I want to resize an image) an uncompressed version of the image is stored in the memory. As a consequence, a 100 kb image (dimensions 5000x5000) may consume the entire memory_limit and therefore be rejected (Fatal error: Allowed memory size of xxxxxxxx bytes exhausted...), while a 900 kb image (1000x1000) may upload without any problems.

The easy solution would be to increase memory_limit etc. in php.ini, but if we are looking at really large dimensions this is not always a good solution. It would consume a lot of memory and could eventually slow down the server.

My questions are therefore:

Are there any alternatives to ImageCreateFromJPEG()?
Are there any libraries or plug-ins that I can install, which are using compressed images instead of uncompressed images?


Thank you and best regards,

Znupi
02-22-2008, 03:06 PM
Imagick (http://php.net/imagick) may do that, I'm not sure, I never worked with it, just thought I'd point it out for you :).

You can use ini_set('memory_limit', '-1');, though.

mago
02-23-2008, 09:11 AM
Dear Znupi,

Thanks for your reply. I'll have a closer at Imagick.

Best regards,