public function resizeFit(&$image, $newWidth, $newHeight)
    {

        $width  = $image->getWidth();
        $height = $image->getHeight();
        $ratio  = $width / $height;

        // Try basing it on width first
        $resizeWidth  = $newWidth;
        $resizeHeight = round($newWidth / $ratio);

        if (($resizeWidth > $newWidth) or ($resizeHeight > $newHeight)) { // Oops, either with or height does not fit
            // So base on height instead
            $resizeHeight = $newHeight;
            $resizeWidth  = $newHeight * $ratio;
        }

        $this->_resize($image, $resizeWidth, $resizeHeight);

        return $this;
    }
public function resizeFit(&$image, $newWidth, $newHeight)
    {

        $width  = $image->getWidth();
        $height = $image->getHeight();
        $ratio  = $width / $height;

        // Try basing it on width first
        $resizeWidth  = $newWidth;
        $resizeHeight = round($newWidth / $ratio);

        if (($resizeWidth > $newWidth) or ($resizeHeight > $newHeight)) { // Oops, either with or height does not fit
            // So base on height instead
            $resizeHeight = $newHeight;
            $resizeWidth  = $newHeight * $ratio;
        }

        $this->_resize($image, $resizeWidth, $resizeHeight);

        return $this;
    }
public function resizeFit ( & $ image , $ newWidth , $ newHeight ) { $ width = $ image -> getWidth ( ) ; $ height = $ image -> getHeight ( ) ; $ ratio = $ width / $ height ; // Try basing it on width first $ resizeWidth = $ newWidth ; $ resizeHeight = round ( $ newWidth / $ ratio ) ; if ( ( $ resizeWidth > $ newWidth ) or ( $ resizeHeight > $ newHeight ) ) { // Oops, either with or height does not fit // So base on height instead $ resizeHeight = $ newHeight ; $ resizeWidth = $ newHeight * $ ratio ; } $ this -> _resize ( $ image , $ resizeWidth , $ resizeHeight ) ; return $ this ; }
Resize image to fit inside the given dimension. No part of the image is lost.

@param Image $image
@param int $newWidth Width in pixels.
@param int $newHeight Height in pixels.

@return self
Resize image to fit inside the given dimension . No part of the image is lost .