Grafika\Gd\Editor::resizeFill PHP Method

resizeFill() public method

Resize image to fill all the space in the given dimension. Excess parts are cropped.
public resizeFill ( Image &$image, integer $newWidth, integer $newHeight ) : Editor
$image Image
$newWidth integer Width in pixels.
$newHeight integer Height in pixels.
return Editor
    public function resizeFill(&$image, $newWidth, $newHeight)
    {
        $width = $image->getWidth();
        $height = $image->getHeight();
        $ratio = $width / $height;
        // Base optimum size on new width
        $optimumWidth = $newWidth;
        $optimumHeight = round($newWidth / $ratio);
        if ($optimumWidth < $newWidth or $optimumHeight < $newHeight) {
            // Oops, where trying to fill and there are blank areas
            // So base optimum size on height instead
            $optimumWidth = $newHeight * $ratio;
            $optimumHeight = $newHeight;
        }
        $this->_resize($image, $optimumWidth, $optimumHeight);
        $this->crop($image, $newWidth, $newHeight);
        // Trim excess parts
        return $this;
    }