tags:

views:

132

answers:

4

I am using imagecreatefromjpeg on a shared host, so if the image is to big then imagecreatefromjpeg will give me an "out of memmory error" and terminate the script.

Is there anyway to catch the out of memmory error, and simply let imagecreatefromjpeg fail(Return false) instead of terminating the script?

+1  A: 

Try working out the size of the image first: http://uk3.php.net/function.getimagesize I believe imagecreatefromjpeg will fall over if the image is bigger than 3000px in any dimension.

Lizard
+1 checking dimensions first is always a good precaution
bobince
he could also check the file size itself.
dusoft
A: 

see this thread:

http://stackoverflow.com/questions/1117344/a-fail-safe-way-to-prevent-gd-image-library-from-running-out-of-memory-php

simple answer is its not easily possible with any degree of certainty

seengee
A: 

does adding @ before the function do any help?

example:

$x=@imagecreatefromjpeg .......

see also how to suppress errors in php: http://us3.php.net/manual/en/language.operators.errorcontrol.php

dusoft
That remove the error message, but the php script stil die.
Martin Tilsted
A: 

Simply enclose your function inside if statements, instructing it to redirect when the function fails.

i.e. if (!imagecreatefromjpeg){//redirect commands here};

George Violaris