From 486743dfcf515bf7d9d22049a63910445fe1a67b Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 3 Feb 2013 13:57:49 +0100 Subject: [PATCH] added brightness and contrast methods --- README.md | 2 ++ src/Intervention/Image/Image.php | 24 ++++++++++++++++++++++++ tests/ImageTest.php | 16 ++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/README.md b/README.md index e12f8763..991c7560 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ Add the facade of this package to the `$aliases` array. * Image::resize - Resize image based on given width and/or height * Image::grab - Cut out a detail of the image in given ratio and resize to output size * Image::insert - Insert another image on top of the current image +* Image::brightness - Changes brightness of current image +* Image::contrast - Changes contrast of current image * Image::pixelate - Pixelate current image * Image::greyscale - Turn current image into a greyscale version * Image::text - Write text in current image diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index 45837dd3..f2a868dc 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -405,6 +405,30 @@ class Image return $this; } + /** + * Changes the brightness of the current image + * + * @param int $level [description] + * @return Image + */ + public function brightness($level) + { + imagefilter($this->resource, IMG_FILTER_BRIGHTNESS, $level); + return $this; + } + + /** + * Changes the contrast of the current image + * + * @param int $level + * @return Image + */ + public function contrast($level) + { + imagefilter($this->resource, IMG_FILTER_CONTRAST, $level); + return $this; + } + /** * Pixelate current image * diff --git a/tests/ImageTest.php b/tests/ImageTest.php index cdc2a87a..2a0f7c65 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -294,4 +294,20 @@ class ImageTest extends PHPUnit_Framework_Testcase } + public function testBrightnessImage() + { + $img = $this->getTestImage(); + $img->brightness(50); + $img->brightness(-50); + $this->assertInstanceOf('Intervention\Image\Image', $img); + } + + public function testContrastImage() + { + $img = $this->getTestImage(); + $img->contrast(50); + $img->contrast(-50); + $this->assertInstanceOf('Intervention\Image\Image', $img); + } + } \ No newline at end of file