protected function getSafeResizeOffset(\Imagick $image, $targetWidth, $targetHeight)
    {
        $source = $image->getImageGeometry();
        if (0 == $targetHeight || ($source['width'] / $source['height']) < ($targetWidth / $targetHeight)) {
            $scale = $source['width'] / $targetWidth;
        } else {
            $scale = $source['height'] / $targetHeight;
        }

        return array('width' => (int) ($source['width'] / $scale), 'height' => (int) ($source['height'] / $scale));
    }
protected function getSafeResizeOffset(\Imagick $image, $targetWidth, $targetHeight)
    {
        $source = $image->getImageGeometry();
        if (0 == $targetHeight || ($source['width'] / $source['height']) < ($targetWidth / $targetHeight)) {
            $scale = $source['width'] / $targetWidth;
        } else {
            $scale = $source['height'] / $targetHeight;
        }

        return array('width' => (int) ($source['width'] / $scale), 'height' => (int) ($source['height'] / $scale));
    }
protected function getSafeResizeOffset ( \ Imagick $ image , $ targetWidth , $ targetHeight ) { $ source = $ image -> getImageGeometry ( ) ; if ( 0 == $ targetHeight || ( $ source [ 'width' ] / $ source [ 'height' ] ) < ( $ targetWidth / $ targetHeight ) ) { $ scale = $ source [ 'width' ] / $ targetWidth ; } else { $ scale = $ source [ 'height' ] / $ targetHeight ; } return array ( 'width' => ( int ) ( $ source [ 'width' ] / $ scale ) , 'height' => ( int ) ( $ source [ 'height' ] / $ scale ) ) ; }
Returns width and height for resizing the image, keeping the aspect ratio
and allow the image to be larger than either the width or height

@param  \Imagick $image
@param  int      $targetWidth
@param  int      $targetHeight
@return array
Returns width and height for resizing the image keeping the aspect ratio and allow the image to be larger than either the width or height