mirror of
https://github.com/Intervention/image.git
synced 2025-08-11 16:34:00 +02:00
added flip 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::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
|
||||||
* Image::rectangle - Draw rectangle in current image starting at point 1 and ending at point 2
|
* 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
|
// 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);
|
||||||
|
|
||||||
|
// flip image horizontally
|
||||||
|
$img->flip('h');
|
||||||
|
|
||||||
|
// flip image vertically
|
||||||
|
$img->flip('v');
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Method chaining
|
#### Method chaining
|
||||||
|
@@ -406,6 +406,31 @@ class Image
|
|||||||
return $this->grab($width, $height);
|
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
|
* Insert another image on top of the current image
|
||||||
*
|
*
|
||||||
|
@@ -183,6 +183,19 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
|||||||
$this->assertEquals($img->height, 200);
|
$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()
|
public function testInsertImage()
|
||||||
{
|
{
|
||||||
$img = $this->getTestImage();
|
$img = $this->getTestImage();
|
||||||
|
Reference in New Issue
Block a user