mirror of
https://github.com/Intervention/image.git
synced 2025-08-23 05:52:47 +02:00
normalized input values of brightness and contrast filters
This commit is contained in:
@@ -47,8 +47,8 @@ Add the facade of this package to the `$aliases` array.
|
|||||||
* Image::resize - Resize current image based on given width and/or height
|
* Image::resize - Resize current 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::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::insert - Insert another image on top of the current image
|
||||||
* Image::brightness - Changes brightness of current image (from -255 to +255)
|
* Image::brightness - Changes brightness of current image (-100 = min brightness, 0 = no change, +100 = max brightness)
|
||||||
* Image::contrast - Changes contrast of current image (from -100 to +100)
|
* Image::contrast - Changes contrast of current image (-100 = min contrast, 0 = no change, +100 = max contrast)
|
||||||
* 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::text - Write text in current image
|
* Image::text - Write text in current image
|
||||||
|
@@ -429,7 +429,15 @@ class Image
|
|||||||
*/
|
*/
|
||||||
public function brightness($level)
|
public function brightness($level)
|
||||||
{
|
{
|
||||||
|
// normalize level
|
||||||
|
if ($level >= -100 && $level <= 100) {
|
||||||
|
$level = $level * 2.55;
|
||||||
|
} else {
|
||||||
|
throw new Exception('Brightness level must be between -100 and +100');
|
||||||
|
}
|
||||||
|
|
||||||
imagefilter($this->resource, IMG_FILTER_BRIGHTNESS, $level);
|
imagefilter($this->resource, IMG_FILTER_BRIGHTNESS, $level);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,7 +449,15 @@ class Image
|
|||||||
*/
|
*/
|
||||||
public function contrast($level)
|
public function contrast($level)
|
||||||
{
|
{
|
||||||
|
// normalize level
|
||||||
|
if ($level >= -100 && $level <= 100) {
|
||||||
|
$level = $level * (-1);
|
||||||
|
} else {
|
||||||
|
throw new Exception('Contrast level must be between -100 and +100');
|
||||||
|
}
|
||||||
|
|
||||||
imagefilter($this->resource, IMG_FILTER_CONTRAST, $level);
|
imagefilter($this->resource, IMG_FILTER_CONTRAST, $level);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,6 +471,7 @@ class Image
|
|||||||
public function pixelate($size = 10, $advanced = true)
|
public function pixelate($size = 10, $advanced = true)
|
||||||
{
|
{
|
||||||
imagefilter($this->resource, IMG_FILTER_PIXELATE, $size, $advanced);
|
imagefilter($this->resource, IMG_FILTER_PIXELATE, $size, $advanced);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,6 +483,7 @@ class Image
|
|||||||
public function grayscale()
|
public function grayscale()
|
||||||
{
|
{
|
||||||
imagefilter($this->resource, IMG_FILTER_GRAYSCALE);
|
imagefilter($this->resource, IMG_FILTER_GRAYSCALE);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,6 +495,7 @@ class Image
|
|||||||
public function greyscale()
|
public function greyscale()
|
||||||
{
|
{
|
||||||
$this->grayscale();
|
$this->grayscale();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,6 +507,7 @@ class Image
|
|||||||
public function reset()
|
public function reset()
|
||||||
{
|
{
|
||||||
$this->setProperties($this->dirname .'/'. $this->basename);
|
$this->setProperties($this->dirname .'/'. $this->basename);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -349,19 +349,47 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
|||||||
public function testBrightnessImage()
|
public function testBrightnessImage()
|
||||||
{
|
{
|
||||||
$img = $this->getTestImage();
|
$img = $this->getTestImage();
|
||||||
$img->brightness(50);
|
$img->brightness(100);
|
||||||
$img->brightness(-50);
|
$img->brightness(-100);
|
||||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testContrastImage()
|
public function testContrastImage()
|
||||||
{
|
{
|
||||||
$img = $this->getTestImage();
|
$img = $this->getTestImage();
|
||||||
$img->contrast(50);
|
$img->contrast(100);
|
||||||
$img->contrast(-50);
|
$img->contrast(-100);
|
||||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBrightnessException()
|
||||||
|
{
|
||||||
|
$img = $this->getTestImage();
|
||||||
|
|
||||||
|
// test exception
|
||||||
|
try {
|
||||||
|
$img->brightness(255);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->fail('An expected exception has not been raised for brightness filter');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testContrastException()
|
||||||
|
{
|
||||||
|
$img = $this->getTestImage();
|
||||||
|
|
||||||
|
// test exception
|
||||||
|
try {
|
||||||
|
$img->contrast(255);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->fail('An expected exception has not been raised for contrast filter');
|
||||||
|
}
|
||||||
|
|
||||||
public function testStaticCallMake()
|
public function testStaticCallMake()
|
||||||
{
|
{
|
||||||
$img = Image::make('public/test.jpg');
|
$img = Image::make('public/test.jpg');
|
||||||
|
Reference in New Issue
Block a user