silverstripe/silverstripe-framework — pull request #2859 by kinglozzer (2014-02-17 22:04:42+00:00)
Title: API: Prevent large images from repeatedly crashing PHP on resize

See #2753 for more discussion.

This is a (late) follow up to the discussion [here](https://groups.google.com/forum/#!searchin/silverstripe-dev/image/silverstripe-dev/B57a3KYeAVQ/fUjsQQnfEPAJ) about GD crashing when attempting to open large or high DPI images.

The Google Group discussion involved ideas around “image unavailable” icons in the CMS, this setup (by storing which manipulation failed) will hopefully pave the way for that functionality to be added later, while addressing the immediate issue of completely crashing entire sections of websites.

Implements the same method for checking available memory as #2569, though it’s different to the [method Ingo suggested](http://php.net/manual/en/function.imagecreatefromjpeg.php#64155). I’m not really sure which is more robust, the method in the php.net comments doesn’t take into account that bits and channels aren’t always present in the image info.

Marked as an API change as I’ve added a few methods to the `Image_Backend` interface. Have only tested the basic functionality so far, unit tests etc are still todo.

Doesn’t cause any issues with the CMS, the images just don’t appear for now:

![screen shot 2014-01-02 at 16 15 27](https://f.cloud.github.com/assets/1655548/1833671/53841ff0-73ce-11e3-8daa-840aa19ddcdd.png)
![screen shot 2014-01-02 at 16 17 23](https://f.cloud.github.com/assets/1655548/1833673/55a842ca-73ce-11e3-8d17-a1820c5bd4bf.png)

All comments welcome.