1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 16:50:07 +02:00

added tests and documentation for rotate method

This commit is contained in:
Oliver Vogel
2013-03-02 12:50:09 +01:00
parent 9efea4b951
commit 199466eb0a
3 changed files with 45 additions and 0 deletions

View File

@@ -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');

View File

@@ -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;
}

View File

@@ -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();