/**
* Rotate an image
*
* @param resource $image Image GD resource
* @param int $angle -360 < x < 360
* @param string|array $bgColor Hex color string, array(red, green, blue) or array(red, green, blue, alpha).
* Where red, green, blue - integers 0-255, alpha - integer 0-127
* @return resource
* @throws \JBZoo\Utils\Exception
*/
public static function rotate($image, $angle, $bgColor = '#000000')
{
// Perform the rotation
$angle = Helper::rotate($angle);
$rgba = Helper::normalizeColor($bgColor);
$bgColor = imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
$newImage = imagerotate($image, -$angle, $bgColor);
Helper::addAlpha($newImage);
return $newImage;
}