Grafika\Gd\Editor::rotate PHP Method

rotate() public method

Rotate an image counter-clockwise.
public rotate ( Image &$image, integer $angle, Color | null $color = null ) : Grafika\EditorInterface
$image Image
$angle integer The angle in degrees.
$color Grafika\Color | null The Color object containing the background color.
return Grafika\EditorInterface An instance of image editor.
    public function rotate(&$image, $angle, $color = null)
    {
        if ($image->isAnimated()) {
            // Ignore animated GIF for now
            return $this;
        }
        $color = $color !== null ? $color : new Color('#000000');
        list($r, $g, $b, $alpha) = $color->getRgba();
        $old = $image->getCore();
        $new = imagerotate($old, $angle, imagecolorallocatealpha($old, $r, $g, $b, $alpha));
        if (false === $new) {
            throw new \Exception('Error rotating image.');
        }
        imagedestroy($old);
        // Free resource
        $image = new Image($new, $image->getImageFile(), $image->getWidth(), $image->getHeight(), $image->getType());
        return $this;
    }