Possible to check if imagecreatefromjpeg is going to cause memory exhausted fatal error before I run it?
<p>I've done some searching for this and I understand that it is not possible to recover from an exhausted memory fatal error.    I have a script that runs imagecreatefromjpeg.  I tried catching the exception, I tried running the function with @ and then checking the return value for null or false,  I tried running it with 'die()'. Nothing works.   So I can't 'recover' from it.   </p>

<p>So is it possible to anticipate it before I get to it?   Is it possible to check the uncompressed size of a jpeg and then die gracefully?   I want to sent a message to my users along the lines of "The image $image is too large to process. You will need to create a thumbnail manually".</p>

<p>My shared host won't allow me to increase memory size beyond 64mb so that's not an option.  My code is as follows...</p>

<pre><code>function createthumb($section,$filename,$constrain=100)
{
    $dir = "$section/thumbs_$constrain";
    if(file_exists($workingdir."$section/thumbs_$constrain/$filename")) return 1; 
    if(!file_exists($dir)) mkdir($dir);

    $src = imagecreatefromjpeg($workingdir."$section/$filename");
...
</code></pre>
