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:
@@ -57,6 +57,7 @@ Add the facade of this package to the `$aliases` array.
|
|||||||
* Image::pixelate - Pixelate current image
|
* Image::pixelate - Pixelate current image
|
||||||
* Image::greyscale - Turn current image into a greyscale version
|
* Image::greyscale - Turn current image into a greyscale version
|
||||||
* Image::invert - Invert colors of current image
|
* Image::invert - Invert colors of current image
|
||||||
|
* Image::rotate - Rotate image by a given value
|
||||||
* Image::flip - Mirror image horizontally or vertically
|
* Image::flip - Mirror image horizontally or vertically
|
||||||
* Image::text - Write text in current image
|
* Image::text - Write text in current image
|
||||||
* Image::fill - Fill image with given color at position x,y
|
* 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
|
// draw a red line from point 10,10 to point 300,300 pixel
|
||||||
$img->line('ae051f', 10, 10, 300, 300);
|
$img->line('ae051f', 10, 10, 300, 300);
|
||||||
|
|
||||||
|
// rotate image 90° clockwise
|
||||||
|
$img->rotate(90);
|
||||||
|
|
||||||
// flip image horizontally
|
// flip image horizontally
|
||||||
$img->flip('h');
|
$img->flip('h');
|
||||||
|
|
||||||
|
@@ -457,8 +457,13 @@ class Image
|
|||||||
*/
|
*/
|
||||||
public function rotate($angle = 0, $color = '#000000', $ignore_transparent = 0)
|
public function rotate($angle = 0, $color = '#000000', $ignore_transparent = 0)
|
||||||
{
|
{
|
||||||
|
// rotate image
|
||||||
$this->resource = imagerotate($this->resource, $angle, $this->parseColor($color), $ignore_transparent);
|
$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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -196,6 +196,42 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
|||||||
$this->assertEquals('#fed78c', $img->pickColor(0, 0, 'hex'));
|
$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()
|
public function testInsertImage()
|
||||||
{
|
{
|
||||||
$img = $this->getTestImage();
|
$img = $this->getTestImage();
|
||||||
|
Reference in New Issue
Block a user