Product_Image::getImageAt PHP Method

getImageAt() public method

This prevents ugly upscaling.
public getImageAt ( integer $width = null, integer $height = null, boolean $upscale = false ) : Image
$width integer [optional]
$height integer [optional]
$upscale boolean [optional]
return Image
    public function getImageAt($width = null, $height = null, $upscale = false)
    {
        if (!$this->owner->exists()) {
            return $this->owner;
        }
        $realWidth = $this->owner->getWidth();
        $realHeight = $this->owner->getHeight();
        if ($width && $height) {
            return $realWidth < $width && $realHeight < $height && !$upscale ? $this->owner : $this->owner->Fit($width, $height);
        } else {
            if ($width) {
                return $realWidth < $width && !$upscale ? $this->owner : $this->owner->ScaleWidth($width);
            } else {
                return $realHeight < $height && !$upscale ? $this->owner : $this->owner->ScaleHeight($height);
            }
        }
    }