Rotate the image by a given degrees

@param int   $degrees
@param int   $background
@param float $alpha

@return static
485123
public function do_rotate($degrees, $background = 0xffffff, $alpha = 1.0)
    {
        $transparent = imagecolorallocatealpha($this->_image, ($background >> 16) & 0xFF, ($background >> 8) & 0xFF,
            $background & 0xFF, $alpha * 127);
        $image = imagerotate($this->_image, 360 - $degrees, $transparent, true);
        imagealphablending($image, false);
        imagesavealpha($image, true);

        imagedestroy($this->_image);
        $this->_image = $image;
        $this->_width = imagesx($image);
        $this->_height = imagesy($image);

        return $this;
    }
518257
public static function rotate($path, $rotate = null)
    {
        if ($rotate === null) {
            $exif = exif_read_data($path);
            switch ($exif["Orientation"]) {
                case 3:
                    $rotate = 180;
                    break;
                case 6:
                    $rotate = 90;
                    break;
                case 8:
                    $rotate = -90;
                    break;
            }
        }
        if (!$rotate) {
            return;
        }

        $format = getimagesize($path)[2];

        $image = static::create($path, $format);

        $rotate = imagerotate($image, $rotate * -1, 0);

        static::save($rotate, $path, $format);
    }
694399
public function fixOrientation()
    {
        if (!in_array(exif_imagetype($this->source->getInfos()), array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM))) {
            return $this;
        }

        if (!extension_loaded('exif')) {
            throw new \RuntimeException('You need to EXIF PHP Extension to use this function');
        }

        $exif = @exif_read_data($this->source->getInfos());

        if ($exif === false || !array_key_exists('Orientation', $exif)) {
            return $this;
        }

        switch ($exif['Orientation']) {
            case 1:
                break;

            case 2:
                $this->flip(false, true);
                break;

            case 3: // 180 rotate left
                $this->rotate(180);
                break;

            case 4: // vertical flip
                $this->flip(true, false);
                break;

            case 5: // vertical flip + 90 rotate right
                $this->flip(true, false);
                $this->rotate(-90);
                break;

            case 6: // 90 rotate right
                $this->rotate(-90);
                break;

            case 7: // horizontal flip + 90 rotate right
                $this->flip(false, true);
                $this->rotate(-90);
                break;

            case 8: // 90 rotate left
                $this->rotate(90);
                break;
        }

        return $this;
    }
498554
public function rotateExif()
    {
        if (!in_array($this->fileType, array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM))) {
            $this->log("Autorotate ignored, EXIF not supported by this filetype.");
            return $this;
        }

        $exif = exif_read_data($this->pathToImage);

        if (!empty($exif['Orientation'])) {
            switch ($exif['Orientation']) {
                case 3:
                    $this->log("Autorotate 180.");
                    $this->rotate(180, $this->bgColor);
                    break;

                case 6:
                    $this->log("Autorotate -90.");
                    $this->rotate(-90, $this->bgColor);
                    break;

                case 8:
                    $this->log("Autorotate 90.");
                    $this->rotate(90, $this->bgColor);
                    break;

                default:
                    $this->log("Autorotate ignored, unknown value as orientation.");
            }
        } else {
            $this->log("Autorotate ignored, no orientation in EXIF.");
        }

        return $this;
    }
1168315
public function colorize($r, $g, $b, $alpha) {
		
		$this -> add(__FUNCTION__, func_get_args());
		return $this;
	}
896882
public static function mergeStyleAndBackground( $background, $style )
    {
        $style = trim( $style, '; ' ) . "; background-image:url({$background});";
        $style = trim( $style, '; ' );

        return $style;
    }
1301949
public function rotate($rotation = 0, $background = 0)
	{
		if (empty($this->resource))
		{
			return false;
		}
		$resource = imagerotate($this->resource, $rotation, $background);
		imagedestroy($this->resource);
		$this->resource = $resource;
	}
1087225
public function rotate($angle) {
    // PHP 5.5 GD bug: https://bugs.php.net/bug.php?id=65148: To prevent buggy
    // behavior on negative multiples of 30 degrees we convert any negative
    // angle to a positive one between 0 and 360 degrees.
    $angle -= floor($angle / 360) * 360;

    // For some rotations that are multiple of 30 degrees, we need to correct
    // an imprecision between GD that uses C floats internally, and PHP that
    // uses C doubles. Also, for rotations that are not multiple of 90 degrees,
    // we need to introduce a correction factor of 0.5 to match the GD
    // algorithm used in PHP 5.5 (and above) to calculate the width and height
    // of the rotated image.
    if ((int) $angle == $angle && $angle % 90 == 0) {
      $imprecision = 0;
      $correction = 0;
    }
    else {
      $imprecision = -0.00001;
      $correction = 0.5;
    }

    // Do the trigonometry, applying imprecision fixes where needed.
    $rad = deg2rad($angle);
    $cos = cos($rad);
    $sin = sin($rad);
    $a = $this->width * $cos;
    $b = $this->height * $sin + $correction;
    $c = $this->width * $sin;
    $d = $this->height * $cos + $correction;
    if ((int) $angle == $angle && in_array($angle, [60, 150, 300])) {
      $a = $this->fixImprecision($a, $imprecision);
      $b = $this->fixImprecision($b, $imprecision);
      $c = $this->fixImprecision($c, $imprecision);
      $d = $this->fixImprecision($d, $imprecision);
    }

    // This is how GD on PHP5.5 calculates the new dimensions.
    $this->boundingWidth = abs((int) $a) + abs((int) $b);
    $this->boundingHeight = abs((int) $c) + abs((int) $d);

    return $this;
  }
463735
public function setFromHex($hex, $alpha = 0)
    {
        if (!preg_match(self::$HexRegex, $hex)) {
            throw new \InvalidArgumentException(sprintf(
                    'Inavlid Hex Color "%s"', $hex
            ));
        }

        $ehex = ltrim($hex, '#');

        if (strlen($ehex) === 3) {
            $ehex = $ehex[0] . $ehex[0] .
                    $ehex[1] . $ehex[1] .
                    $ehex[2] . $ehex[2];
        }

        $color = array_map('hexdec', str_split($ehex, 2));

        return $this->setRed($color[0])
                        ->setGreen($color[1])
                        ->setBlue($color[2])
                        ->setAlpha($alpha);
    }
872384
function rotate($angle, $do = false) {
		$angle = min(max(floatval($angle), -360), 360);
        if (!$do){
            $this->_transforms[] = array('rotate', array($angle, true));
            $this->_transforms_str.='rotate('.$angle.')';
        }else{
            $rgba = array(255,255,255,0);
            $handler = $this->handler();
            $bg_color = imagecolorallocatealpha($handler, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
            $new = imagerotate($handler, $angle, $bg_color);
            imagesavealpha($new, true);
            imagealphablending($new, true);
            $this->_info['width'] = imagesx($new);
            $this->_info['height'] = imagesy($new);
            imagedestroy($this->_handler);
            $this->_handler = $new;
        }
		return $this;
	}
772117
public function rotate($degrees, $bgcolor = 0, $transparent = 0) {

		if(false === ('-' . intval($degrees) == '-' . $degrees)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($degrees)), E_USER_ERROR);
		}

		if(false === ('-' . intval($bgcolor) == '-' . $bgcolor)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($bgcolor)), E_USER_ERROR);
		}

		if(false === ('-' . intval($transparent) == '-' . $transparent)) {
			return trigger_error(sprintf('Argument 3 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($transparent)), E_USER_ERROR);
		}

		$this -> add(__FUNCTION__, func_get_args());
		return $this;
	}
947228
public static function si($foreground, $background, $options = [])
	{
		return static::stack($options)->icon($foreground)->on($background);
	}
947233
public function rotate($degrees)
    {
        $resampleImageResource =& $this->getResampleImageResource();

        // Set the background color
        // This won't work with transparent PNG files so we are
        // going to have to figure out how to determine the color
        // of the alpha channel in a future release.
        $alphaChannel = imagecolorallocate($resampleImageResource, 255, 255, 255);

        // Rotate it!
        $this->resampleImageResource = imagerotate($resampleImageResource, $degrees, $alphaChannel);
    }
651940
public function drawAlphaPixel($X, $Y, $Alpha, $R, $G, $B)
    {
        if (isset($this->Mask[$X]) && isset($this->Mask[$X][$Y])) {
            return 0;
        }

        if ($X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize) {
            return -1;
        }
        if ($R < 0) {
            $R = 0;
        } if ($R > 255) {
            $R = 255;
        }
        if ($G < 0) {
            $G = 0;
        } if ($G > 255) {
            $G = 255;
        }
        if ($B < 0) {
            $B = 0;
        } if ($B > 255) {
            $B = 255;
        }

        if ($this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0) {
            $AlphaFactor = floor(($Alpha / 100) * $this->Shadowa);
            $ShadowColor = $this->allocateColor(
                $this->Picture,
                $this->ShadowR,
                $this->ShadowG,
                $this->ShadowB,
                $AlphaFactor
            );
            imagesetpixel($this->Picture, $X + $this->ShadowX, $Y + $this->ShadowY, $ShadowColor);
        }

        $C_Aliased = $this->allocateColor($this->Picture, $R, $G, $B, $Alpha);
        imagesetpixel($this->Picture, $X, $Y, $C_Aliased);
    }
930297
public function rotate($value = 90, $bgColor = 'transparent')
		# Author:     Jarrod Oberto
		# Date:       07-05-2011
		# Purpose:    Rotate image
		# Param in:   (mixed) $degrees: (int) number of degress to rotate image
		#               (str) param "left": rotate left
		#               (str) param "right": rotate right
		#               (str) param "upside": upside-down image
		# Param out:
		# Reference:
		# Notes:    The default direction of imageRotate() is counter clockwise.
		#
	{
		if ($this->imageResized)
		{

			if (is_integer($value))
			{
				$degrees = $value;
			}

			// *** Convert color
			$rgbArray = $this->formatColor($bgColor);
			$r = $rgbArray['r'];
			$g = $rgbArray['g'];
			$b = $rgbArray['b'];
			if (isset($rgbArray['a']))
			{
				$a = $rgbArray['a'];
			}

			if (is_string($value))
			{

				$value = fix_strtolower($value);

				switch ($value)
				{
					case 'left':
						$degrees = 90;
						break;
					case 'right':
						$degrees = 270;
						break;
					case 'upside':
						$degrees = 180;
						break;
					default:
						break;
				}

			}

			// *** The default direction of imageRotate() is counter clockwise
			//   * This makes it clockwise
			$degrees = 360 - $degrees;

			// *** Create background color
			$bg = ImageColorAllocateAlpha($this->imageResized, $r, $g, $b, $a);

			// *** Fill with background
			ImageFill($this->imageResized, 0, 0, $bg);

			// *** Rotate
			$this->imageResized = imagerotate($this->imageResized, $degrees, $bg); // Rotate 45 degrees and allocated the transparent colour as the one to make transparent (obviously)

			// Ensure alpha transparency
			ImageSaveAlpha($this->imageResized, true);

		}
	}
843343
def rotate(x, y, degree):
    
    radian = float(degree) * 2 * math.pi / 360.0
    newx = math.cos(radian) * x - math.sin(radian) * y
    newy = math.sin(radian) * x + math.cos(radian) * y
    return (newx, newy)
932671
public function rotate($degree, ColorInterface $background = null)
    {
        return $this->apply(new Rotate($degree, $background));
    }