elFinder\elFinderVolumeDriver::imgCrop PHP Méthode

imgCrop() protected méthode

Crop image
Author: Dmitry (dio) Levashov
Author: Alexey Sukhotin
protected imgCrop ( string $path, integer $width, integer $height, boolean $x, boolean $y, string $destformat = null ) : string | false
$path string image file
$width integer crop width
$height integer crop height
$x boolean crop left offset
$y boolean crop top offset
$destformat string image destination format
Résultat string | false
    protected function imgCrop($path, $width, $height, $x, $y, $destformat = null)
    {
        if (($s = @getimagesize($path)) == false) {
            return false;
        }
        $result = false;
        switch ($this->imgLib) {
            case 'imagick':
                try {
                    $img = new imagick($path);
                } catch (Exception $e) {
                    return false;
                }
                $img->cropImage($width, $height, $x, $y);
                $result = $img->writeImage($path);
                return $result ? $path : false;
                break;
            case 'gd':
                $img = self::gdImageCreate($path, $s['mime']);
                if ($img && false != ($tmp = imagecreatetruecolor($width, $height))) {
                    self::gdImageBackground($tmp, $this->options['tmbBgColor']);
                    $size_w = $width;
                    $size_h = $height;
                    if ($s[0] < $width || $s[1] < $height) {
                        $size_w = $s[0];
                        $size_h = $s[1];
                    }
                    if (!imagecopy($tmp, $img, 0, 0, $x, $y, $size_w, $size_h)) {
                        return false;
                    }
                    $result = self::gdImage($tmp, $path, $destformat, $s['mime']);
                    imagedestroy($img);
                    imagedestroy($tmp);
                    return $result ? $path : false;
                }
                break;
        }
        return false;
    }