BxDolImageResize::crop PHP Method

crop() public method

Crop image
public crop ( $iScaledWidth, $iScaledHeight, $x, $y, $iCroppedWidth, $iCroppedHeight, $iRotation, $sSrcImage, $sDstImage = '' ) : true
$iScaledWidth - scaled img width
$iScaledHeight - scaled img height
$x - cropped area coord
$y - cropped area coord
$iCroppedWidth - cropped area width
$iCroppedHeight - cropped area height
$iRotation - img rotation
$sSrcImage - source image
$sDstImage - destination image, leave empty to overwrite $sSrcImage
return true on success, false on error
    function crop($iScaledWidth, $iScaledHeight, $x, $y, $iCroppedWidth, $iCroppedHeight, $iRotation, $sSrcImage, $sDstImage = '')
    {
        $iScaledWidth = round($iScaledWidth);
        $iScaledHeight = round($iScaledHeight);
        $this->_sError = '';
        try {
            $o = $this->_oManager->make($sSrcImage)->resize($iScaledWidth, $iScaledHeight)->rotate($iRotation);
            $iImgRotWidth = $o->width();
            $iImgRotHeight = $o->height();
            $dx = round(($iImgRotWidth - $iScaledWidth) / 2);
            $dy = round(($iImgRotHeight - $iScaledHeight) / 2);
            $o->crop($iScaledWidth, $iScaledHeight, $dx, $dy)->crop(round($iCroppedWidth), round($iCroppedHeight), $x, $y)->save($sDstImage ? $sDstImage : $sSrcImage, $this->_iJpegQuality);
        } catch (Exception $e) {
            $this->_sError = $e->getMessage();
            return IMAGE_ERROR_WRONG_TYPE;
        }
        return IMAGE_ERROR_SUCCESS;
    }