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;
}