JBZoo\Image\Image::crop PHP Method

crop() public method

Crop an image
public crop ( integer $left, integer $top, integer $right, integer $bottom )
$left integer Left
$top integer Top
$right integer Right
$bottom integer Bottom
    public function crop($left, $top, $right, $bottom)
    {
        $left = VarFilter::int($left);
        $top = VarFilter::int($top);
        $right = VarFilter::int($right);
        $bottom = VarFilter::int($bottom);
        // Determine crop size
        if ($right < $left) {
            list($left, $right) = array($right, $left);
        }
        if ($bottom < $top) {
            list($top, $bottom) = array($bottom, $top);
        }
        $cropedW = $right - $left;
        $cropedH = $bottom - $top;
        // Perform crop
        $newImage = imagecreatetruecolor($cropedW, $cropedH);
        Helper::addAlpha($newImage);
        imagecopyresampled($newImage, $this->_image, 0, 0, $left, $top, $cropedW, $cropedH, $cropedW, $cropedH);
        // Update meta data
        $this->_replaceImage($newImage);
        $this->_width = $cropedW;
        $this->_height = $cropedH;
        return $this;
    }