1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-18 04:38:26 +01:00

added flip method

This commit is contained in:
Oliver Vogel 2013-03-02 12:30:59 +01:00
parent 54462c777f
commit 1a8b4749cf
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::flip - Mirror image horizontally or vertically
* Image::text - Write text in current image
* Image::fill - Fill image with given color at position x,y
* Image::rectangle - Draw rectangle in current image starting at point 1 and ending at point 2
@ -186,6 +187,12 @@ $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);
// flip image horizontally
$img->flip('h');
// flip image vertically
$img->flip('v');
```
#### Method chaining

View File

@ -406,6 +406,31 @@ class Image
return $this->grab($width, $height);
}
public function flip($mode = null)
{
$x = 0;
$y = 0;
$width = $this->width;
$height = $this->height;
switch (strtolower($mode)) {
case 2:
case 'v':
case 'vert':
case 'vertical':
$y = $height - 1;
$height = $height * (-1);
break;
default:
$x = $width - 1;
$width = $width * (-1);
break;
}
return $this->modify(0, 0, $x, $y, $this->width, $this->height, $width, $height);
}
/**
* Insert another image on top of the current image
*

View File

@ -183,6 +183,19 @@ class ImageTest extends PHPUnit_Framework_Testcase
$this->assertEquals($img->height, 200);
}
public function testFlipImage()
{
$img = $this->getTestImage();
$img->flip('h');
$this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertEquals('#ffbf47', $img->pickColor(0, 0, 'hex'));
$img = $this->getTestImage();
$img->flip('v');
$this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertEquals('#fed78c', $img->pickColor(0, 0, 'hex'));
}
public function testInsertImage()
{
$img = $this->getTestImage();