Grafika\Imagick\Editor::crop PHP Method

crop() public method

Crop the image to the given dimension and position.
public crop ( Image &$image, integer $cropWidth, integer $cropHeight, string $position = 'center', integer $offsetX, integer $offsetY ) : Editor
$image Image
$cropWidth integer Crop width in pixels.
$cropHeight integer Crop Height in pixels.
$position string The crop position. Possible values top-left, top-center, top-right, center-left, center, center-right, bottom-left, bottom-center, bottom-right and smart. Defaults to center.
$offsetX integer Number of pixels to add to the X position of the crop.
$offsetY integer Number of pixels to add to the Y position of the crop.
return Editor
    public function crop(&$image, $cropWidth, $cropHeight, $position = 'center', $offsetX = 0, $offsetY = 0)
    {
        if ($image->isAnimated()) {
            // Ignore animated GIF for now
            return $this;
        }
        if ('smart' === $position) {
            // Smart crop
            list($x, $y) = $this->_smartCrop($image, $cropWidth, $cropHeight);
        } else {
            // Turn into an instance of Position
            $position = new Position($position, $offsetX, $offsetY);
            // Crop position as x,y coordinates
            list($x, $y) = $position->getXY($image->getWidth(), $image->getHeight(), $cropWidth, $cropHeight);
        }
        $x += $offsetX;
        $y += $offsetY;
        $image->getCore()->cropImage($cropWidth, $cropHeight, $x, $y);
        return $this;
    }