PHP | Problem - Two Image Transformations on Custom Image Method
// This returns a filename, I'd like to return an image object.
class AdvancedImage extends Image {
public function ExactSize($idealWidth=900,$idealHeight=600){
$imageWidth = $this->getWidth();
$imageHeight = $this->getHeight();
$imageRatio = $imageWidth / $imageHeight;
$endRatio = ($idealWidth > 0 && $idealHeight > 0) ? $idealWidth / $idealHeight : 0;
if($imageRatio > $endRatio){
//Size imageHeight to idealHeight
$resizedImage = $this->getFormattedImage("SetRatioSize", ($idealHeight * $imageRatio), $idealHeight);
} elseif($imageRatio < $endRatio) {
//Size imageWidth to idealWidth
$resizedImage = $this->getFormattedImage("SetRatioSize", $idealWidth, ($idealWidth / $imageRatio));
} else {
$resizedImage = $this->getFormattedImage("SetRatioSize", $idealWidth, $idealHeight);
}
$croppedImage = $resizedImage->cacheFilename("CroppedImage", $idealWidth, $idealHeight);
return $croppedImage;
}
23/01/2012 8:25pm
PHP | Solution - Tama
See Pyromanik's solution to this: http://www.sspaste.com/paste/show/4f1cd4494bb76