diff --git a/README.md b/README.md index 5136b996..2505ebc7 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Add the facade of this package to the `$aliases` array. * Image::pixelate - Pixelate current image * Image::greyscale - Turn current image into a greyscale version * Image::invert - Invert colors of current image +* Image::rotate - Rotate image by a given value * Image::flip - Mirror image horizontally or vertically * Image::text - Write text in current image * Image::fill - Fill image with given color at position x,y @@ -188,6 +189,9 @@ $img->circle('ae051f', 400, 300, 100, false); // draw a red line from point 10,10 to point 300,300 pixel $img->line('ae051f', 10, 10, 300, 300); +// rotate image 90° clockwise +$img->rotate(90); + // flip image horizontally $img->flip('h'); diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index ce00629d..2da7ef2a 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -457,8 +457,13 @@ class Image */ public function rotate($angle = 0, $color = '#000000', $ignore_transparent = 0) { + // rotate image $this->resource = imagerotate($this->resource, $angle, $this->parseColor($color), $ignore_transparent); + // re-read width/height + $this->width = imagesx($this->resource); + $this->height = imagesy($this->resource); + return $this; } diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 5d4ffa68..07b4010b 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -196,6 +196,42 @@ class ImageTest extends PHPUnit_Framework_Testcase $this->assertEquals('#fed78c', $img->pickColor(0, 0, 'hex')); } + public function testRotateImage() + { + $img = $this->getTestImage(); + $img->rotate(90); + $img->save('public/rotate.jpg'); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 600); + $this->assertEquals($img->height, 800); + $this->assertEquals('#ffbf47', $img->pickColor(0, 0, 'hex')); + + $img = $this->getTestImage(); + $img->rotate(180); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 800); + $this->assertEquals($img->height, 600); + $this->assertEquals('#ffa600', $img->pickColor(0, 0, 'hex')); + + // rotate transparent png and keep transparency + $img = Image::make('public/circle.png'); + $img->rotate(180); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 50); + $this->assertEquals($img->height, 50); + $checkColor = $img->pickColor(0, 0, 'array'); + $this->assertEquals($checkColor['red'], 0); + $this->assertEquals($checkColor['green'], 0); + $this->assertEquals($checkColor['blue'], 0); + $this->assertEquals($checkColor['alpha'], 127); + } + public function testInsertImage() { $img = $this->getTestImage();