public \Joomla\CMS\Image\Image
rotate
(mixed $angle, mixed $background = -1, mixed $createNew = true)
/**
* Method to rotate the current image.
*
* @param mixed $angle The angle of rotation for the image
* @param integer $background The background color to use when areas are added due to rotation
* @param boolean $createNew If true the current image will be cloned, rotated and returned; else
* the current image will be rotated and returned.
*
* @return Image
*
* @since 2.5.0
* @throws \LogicException
*/
public function rotate($angle, $background = -1, $createNew = true)
{
// Sanitize input
$angle = (float) $angle;
// Create the new truecolor image handle.
$handle = imagecreatetruecolor($this->getWidth(), $this->getHeight());
// Make background transparent if no external background color is provided.
if ($background == -1) {
// Allow transparency for the new image handle.
imagealphablending($handle, false);
imagesavealpha($handle, true);
$background = imagecolorallocatealpha($handle, 0, 0, 0, 127);
}
// Copy the image
imagecopy($handle, $this->getHandle(), 0, 0, 0, 0, $this->getWidth(), $this->getHeight());
// Rotate the image
$handle = imagerotate($handle, $angle, $background);
// If we are resizing to a new image, create a new Image object.
if ($createNew) {
return new static($handle);
}
// Swap out the current handle for the new image handle.
$this->destroy();
$this->handle = $handle;
return $this;
}