Rotate the image by a given degrees

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

@return static
508716
public function do_rotate($degrees, $background = 0xffffff, $alpha = 1.0)
    {
        $backgroundColor = sprintf('rgba(%u,%u,%u,%f)', ($background >> 16) & 0xFF, ($background >> 8) & 0xFF,
            $background & 0xFF, $alpha);
        $this->_image->rotateImage(new \ImagickPixel($backgroundColor), $degrees);
        $this->_image->setImagePage($this->_width, $this->_height, 0, 0);

        $this->_width = $this->_image->getImageWidth();
        $this->_height = $this->_image->getImageHeight();

        return $this;
    }
895059
public function roundedCorners(int $radius, string $background_color, int $aa_level = 4)
    {
        $this->actions_to_perform[] = ['roundedCorners', ['radius' => $radius, 'background_color' => $background_color, 'aa_lvl' => $aa_level]];

        return $this;
    }
1223548
public static function rotateImage( $imageUri, $angle, $quality = 100 )
	{
		$modifier	= new UI_Image_Rotator( $imageUri, $imageUri, $quality );
		return $modifier->rotate( $angle );
	}
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);

		}
	}
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;
    }
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;
	}
1106945
public function alpha($alpha = null)
    {
        if ($alpha !== null) {
            $this->alpha = $alpha <= 1 ? $alpha : 1;
            return $this;
        }
        return $this->alpha;
    }
343167
public function rotate($angle, $x = -1, $y = -1)
    {
        if ($x == -1) {
            $x = $this->x;
        }
        if ($y == -1) {
            $y = $this->y;
        }
        if ($this->angle!=0) {
            $this->_out('Q');
        }
        $this->angle = $angle;
        if ($angle != 0) {
            $angle*=M_PI/180;
            $c=cos($angle);
            $s=sin($angle);
            $cx=$x*$this->k;
            $cy=($this->h-$y)*$this->k;
            $this->_out(sprintf(
                'q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',
                $c,
                $s,
                -$s,
                $c,
                $cx,
                $cy,
                -$cx,
                -$cy
            ));
        }
    }
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;
	}
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;
    }
911247
@Override
    public void load(boolean alpha)
    {
        ImageBuffer surface = Graphics.getImageBuffer(media);

        if (0 != Double.compare(factorH, 1.0) || 0 != Double.compare(factorV, 1.0))
        {
            final int x = (int) (surface.getWidth() * factorH);
            final int y = (int) (surface.getHeight() * factorV);
            surface = Graphics.resize(surface, x, y);
        }

        lineWidth = (int) Math.floor(surface.getWidth() * sx / 100.0);
        lineHeight = (int) Math.floor(surface.getHeight() / (double) linesNumber * sy / 100.0);
        lines = Graphics.splitImage(surface, 1, linesNumber);

        final double factH = sx / 100.0 / AMPLITUDE_FACTOR;

        for (int i = 0; i < linesNumber; i++)
        {
            final int width = (int) Math.ceil(lines[i].getWidth() * (sx + i * 2 * factH) / 100);
            final int height = lines[i].getHeight() * sy / 100;
            lines[i] = Graphics.resize(lines[i], width, height);
        }
    }
1220455
public static BufferedImage rotate(BufferedImage image, int angle)
    {
        final int width = image.getWidth();
        final int height = image.getHeight();
        final int transparency = image.getColorModel().getTransparency();

        final Rectangle rectangle = new Rectangle(0, 0, width, height);
        rectangle.rotate(angle);

        final BufferedImage rotated = createImage(rectangle.getWidth(), rectangle.getHeight(), transparency);
        final Graphics2D g = rotated.createGraphics();

        optimizeGraphicsSpeed(g);
        g.rotate(Math.toRadians(angle), rectangle.getWidth() / 2.0, rectangle.getHeight() / 2.0);

        final double ox = rectangle.getWidth() - (double) width;
        final double oy = rectangle.getHeight() - (double) height;
        final double cos = UtilMath.cos(angle);
        final double sin = UtilMath.sin(angle);
        final double angleOffsetX = sin * ox + cos * oy;
        final double angleOffsetY = -sin * oy + cos * ox;

        g.drawImage(image, null, (int) ((ox - angleOffsetX) / 2.0), (int) ((oy - angleOffsetY) / 2.0));
        g.dispose();

        return rotated;
    }
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);
    }
932671
public function rotate($degree, ColorInterface $background = null)
    {
        return $this->apply(new Rotate($degree, $background));
    }
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);
    }
205704
public static void rotate(Image image, int degree, OutputStream out) throws IORuntimeException {
		writeJpg(rotate(image, degree), getImageOutputStream(out));
	}
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);
    }