Is there a way to prevent running out of memory in the PHP GD image library ? If too large an image is loaded, GD has a limited amount of memory, ending with a script. I would like him to throw a spectacular exception or something like that, but, alas, he doesn’t.
Now I am using a cobbled-together script, which first produces ini_set('memory_limit', '128M'), if this works, I am usually set up. Depending on the configuration of the server, although this may not be possible, therefore I abandon the algorithm that tries to estimate the amount of memory required (taking into account the resolution, color depth, channels and fudge ratio), then compares it with memory_get_usage()if the function exists, otherwise case a rough estimate.
All this still works, but it is far from elegant, and I'm not sure in some cases. Is there a better way to do this, i.e. If GD gracefully crashes, if necessary, instead of soaking it all up?
source
share