public function Fit($width, $height)
    {
        $width = $this->castDimension($width, 'Width');
        $height = $this->castDimension($height, 'Height');
        // Item must be regenerated
        $variant = $this->variantName(__FUNCTION__, $width, $height);
        return $this->manipulateImage($variant, function (Image_Backend $backend) use ($width, $height) {
            // Check if image is already sized to the correct dimension
            $currentWidth = $backend->getWidth();
            $currentHeight = $backend->getHeight();
            if (!$currentWidth || !$currentHeight) {
                return null;
            }
            $widthRatio = $width / $currentWidth;
            $heightRatio = $height / $currentHeight;

            if ($widthRatio < $heightRatio) {
                // Target is higher aspect ratio than image, so check width
                if ($currentWidth === $width) {
                    return $this;
                }
            } else {
                // Target is wider or same aspect ratio as image, so check height
                if ($currentHeight === $height) {
                    return $this;
                }
            }

            return $backend->resizeRatio($width, $height);
        });
    }
public function Fit($width, $height)
    {
        $width = $this->castDimension($width, 'Width');
        $height = $this->castDimension($height, 'Height');
        // Item must be regenerated
        $variant = $this->variantName(__FUNCTION__, $width, $height);
        return $this->manipulateImage($variant, function (Image_Backend $backend) use ($width, $height) {
            // Check if image is already sized to the correct dimension
            $currentWidth = $backend->getWidth();
            $currentHeight = $backend->getHeight();
            if (!$currentWidth || !$currentHeight) {
                return null;
            }
            $widthRatio = $width / $currentWidth;
            $heightRatio = $height / $currentHeight;

            if ($widthRatio < $heightRatio) {
                // Target is higher aspect ratio than image, so check width
                if ($currentWidth === $width) {
                    return $this;
                }
            } else {
                // Target is wider or same aspect ratio as image, so check height
                if ($currentHeight === $height) {
                    return $this;
                }
            }

            return $backend->resizeRatio($width, $height);
        });
    }
public function Fit ( $ width , $ height ) { $ width = $ this -> castDimension ( $ width , 'Width' ) ; $ height = $ this -> castDimension ( $ height , 'Height' ) ; // Item must be regenerated $ variant = $ this -> variantName ( __FUNCTION__ , $ width , $ height ) ; return $ this -> manipulateImage ( $ variant , function ( Image_Backend $ backend ) use ( $ width , $ height ) { // Check if image is already sized to the correct dimension $ currentWidth = $ backend -> getWidth ( ) ; $ currentHeight = $ backend -> getHeight ( ) ; if ( ! $ currentWidth || ! $ currentHeight ) { return null ; } $ widthRatio = $ width / $ currentWidth ; $ heightRatio = $ height / $ currentHeight ; if ( $ widthRatio < $ heightRatio ) { // Target is higher aspect ratio than image, so check width if ( $ currentWidth === $ width ) { return $ this ; } } else { // Target is wider or same aspect ratio as image, so check height if ( $ currentHeight === $ height ) { return $ this ; } } return $ backend -> resizeRatio ( $ width , $ height ) ; } ) ; }
Scale image proportionally to fit within the specified bounds

@param int $width The width to size within
@param int $height The height to size within
@return AssetContainer
Scale image proportionally to fit within the specified bounds