I'm finishing up a project at the moment and one minor to-do is left - visitors on the website can generate and save PDF files for instances of a DataObject class on the website, which have images linked to them. The PDF displays the DataObject's main image in it, on top of a polaroid background sprite.
In order to place the image exactly on top of the polaroid part of the background, it is first resized depending on its orientation (orientation 0 = SetSize, 1 = SetWidth, 2 = SetHeight). This keeps the aspect ratio of the image intact while making sure that at least one dimension of the image fits inside the polaroid. Unless the image is square (very rare), it still overflows one of the dimensions though.
Now we can just display the image at the maximum width and height allowed within the polaroid and we'd be done, but this defeats the purpose of resizing it in the first place because it would still end up skewed. So after the first resize (see previous paragraph), I've added in another line whcih uses the CroppedImage method of the Image class, to just "cut off" any part of the image which doesn't fit inside the polaroid. This way, most of the image is still showed and it doesn't become skewed. On the frontend some CSS (overflow: hidden) would suffice, but this doesn't seem to be possible in FPDF (the PDF extension we're using), which is why I'm trying to achieve the cropping this way.
The problem is, SilverStripe only seems to let me do one or the other - SetSize/-Width/-Height OR CroppedImage. If I try to consecutively execute both methods, the object variable turns into NULL, rendering it useless. I'm guessing this is because of all of these methods turning the Image object into an instance of Image_Cached? Does anyone have any ideas on this?
I've tried creating a new instance of Image and storing the resized image into it, then cropping that new instance. But it didn't get me anywhere. I can't use the GD2 methods because I don't think the server supports them; "GD Support" is "enabled" in phpinfo() but I get the "the method 'croppedresize' does not exist on 'Image'" error when I try to use one of the methods. SilverStripe version is 2.4.3.
Sorry for the long post (I have a habit of being long-winded), I hope it's clear what the problem is.