elFinder\elFinderVolumeDriver::imgRotate PHP Method

imgRotate() protected method

Rotate image
Author: nao-pon
Author: Troex Nevelin
protected imgRotate ( string $path, integer $degree, string $bgcolor = '#ffffff', string $destformat = null ) : string | false
$path string image file
$degree integer rotete degrees
$bgcolor string square background color in #rrggbb format
$destformat string image destination format
return string | false
    protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $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->rotateImage(new ImagickPixel($bgcolor), $degree);
                $result = $img->writeImage($path);
                return $result ? $path : false;
                break;
            case 'gd':
                $img = self::gdImageCreate($path, $s['mime']);
                $degree = 360 - $degree;
                list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
                $bgcolor = imagecolorallocate($img, $r, $g, $b);
                $tmp = imageRotate($img, $degree, (int) $bgcolor);
                $result = self::gdImage($tmp, $path, $destformat, $s['mime']);
                imageDestroy($img);
                imageDestroy($tmp);
                return $result ? $path : false;
                break;
        }
        return false;
    }