protected function _do_rotate($degrees)
{
if (!function_exists('imagerotate')) {
throw new CException('This method requires imagerotate, which is only available in the bundled version of GD');
}
// Loads image if not yet loaded
$this->_load_image();
// Transparent black will be used as the background for the uncovered region
$transparent = imagecolorallocatealpha($this->_image, 0, 0, 0, 127);
// Rotate, setting the transparent color
$image = imagerotate($this->_image, 360 - $degrees, $transparent, 1);
// Save the alpha of the rotated image
imagesavealpha($image, TRUE);
// Get the width and height of the rotated image
$width = imagesx($image);
$height = imagesy($image);
if (imagecopymerge($this->_image, $image, 0, 0, 0, 0, $width, $height, 100)) {
// Swap the new image for the old one
imagedestroy($this->_image);
$this->_image = $image;
// Reset the width and height
$this->width = $width;
$this->height = $height;
}
}