From 291a13927b45f41acc313c1eea9a1e0566c140ae Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Fri, 1 Mar 2013 16:53:57 +0100 Subject: [PATCH] added invert method --- README.md | 1 + src/Intervention/Image/Image.php | 12 ++++++++++++ tests/ImageTest.php | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/README.md b/README.md index cd39f658..cd7b7e0f 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Add the facade of this package to the `$aliases` array. * Image::contrast - Changes contrast of current image (-100 = min contrast, 0 = no change, +100 = max contrast) * Image::pixelate - Pixelate current image * Image::greyscale - Turn current image into a greyscale version +* Image::invert - Invert colors of current image * 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 diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index 9d7f467a..3336cfd3 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -626,6 +626,18 @@ class Image return $this; } + /** + * Invert colors of current image + * + * @return Image + */ + public function invert() + { + imagefilter($this->resource, IMG_FILTER_NEGATE); + + return $this; + } + /** * Reset to original image resource * diff --git a/tests/ImageTest.php b/tests/ImageTest.php index b6b25104..f35e42c2 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -205,6 +205,14 @@ class ImageTest extends PHPUnit_Framework_Testcase $this->assertInstanceOf('Intervention\Image\Image', $img); } + public function testInvertImage() + { + $img = $this->getTestImage(); + $img->invert(); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertEquals('#000000', $img->pickColor(0, 0, 'hex')); + } + public function testFillImage() { $img = $this->getTestImage();