src/Extension/ProductImageExtension.php
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);
            }
        }
    }
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);
            }
        }
    }
Resizes image by width or height only if the source image is bigger than the given width/height.
This prevents ugly upscaling.

@param int  $width   [optional]
@param int  $height  [optional]
@param bool $upscale [optional]

@return Image