Tuesday, 27 August 2013

PHP Fatal Error: Out of Memory when creating an image

PHP Fatal Error: Out of Memory when creating an image

I have a simple PHP script that takes an image that's been uploaded and
processes it with imagecreatefromjpeg. It works great on small images, but
not on larger ones. With an image of say, 5,799,936 bytes, I get the
following error:
Fatal error: Out of memory (allocated 56623104) (tried to allocate 3072
bytes)
If the image is less than 1MB, I get no such error.
I've ensured that I always use imagedestroy whenever an image has been
successfully processed, and I've used memory_get_usage() to see what's
currently in use (186260).
Is there anyway to get to the bottom of this error and change the outcome
-- or do I need to put a check in place for the size of the image, as the
server will never be able to process anything of that size. (If so, how
can I tell what size is OK for the server?)

No comments:

Post a Comment