ManaPHP\Image::resizeCropCenter PHP Method

resizeCropCenter() public method

Resize the image by a given width and height
public resizeCropCenter ( integer $width, integer $height ) : static
$width integer
$height integer
return static
    public function resizeCropCenter($width, $height)
    {
        $_width = $this->adapter->getWidth();
        $_height = $this->adapter->getHeight();
        if ($_width / $_height > $width / $height) {
            $crop_height = $_height;
            $crop_width = $width * $crop_height / $height;
            $offsetX = ($_width - $crop_width) / 2;
            $offsetY = 0;
        } else {
            $crop_width = $_width;
            $crop_height = $height * $crop_width / $width;
            $offsetY = ($_height - $crop_height) / 2;
            $offsetX = 0;
        }
        $this->crop($crop_width, $crop_height, $offsetX, $offsetY);
        $this->scale($width / $crop_width);
        return $this;
    }