silverstripe/sapphire — pull request #1311 by tractorcow (2013-03-20 00:29:08+00:00)
Title: API Better detection and prevention of image resampling

An earlier fix to the Image class https://github.com/silverstripe/sapphire/commit/627a2916f48af24d399ad6e06fe97cde117fc776 allowed the SetWidth, SetHeight and SetSize functions detect whether a resize is necessary.

There are other functions in the class that would benefit from having a similar approach. Rather than implement a new function for each of the generation methods (CroppedImage, etc) I propose changing the convention to check for image dimension changes in getFormattedImage, unless a specific method (such as setHeight) explicitly opts out of it.

Personally I feel a bit conflicted about the solution I've found, as the new behaviour is enabled by default (and thus for all internal methods that use both $arg1 and $arg2). This means any existing user code that adds generation methods where $arg1 and $arg2 are used as values other than width and height (skewing?) will require a custom function calling getFormattedImage with the fourth parameter set to false.

If this is a problem then I could simple make false the default (thus preserving true backwards compatibility) but then I'd add a new method for each of the generation functions (thus bloating code).

Thorough test cases included.