23/01/2012 4:09am

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;
}


Post Comment