mirror of
https://github.com/Intervention/image.git
synced 2025-08-19 12:11:26 +02:00
added colorize method
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Exception;
|
||||||
|
|
||||||
|
class ColorizeOutOfBoundsException extends \OutOfBoundsException
|
||||||
|
{
|
||||||
|
# nothing to override
|
||||||
|
}
|
@@ -1275,6 +1275,37 @@ class Image
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply colorize filter to current image
|
||||||
|
*
|
||||||
|
* @param integer $red
|
||||||
|
* @param integer $green
|
||||||
|
* @param integer $blue
|
||||||
|
* @return Image
|
||||||
|
*/
|
||||||
|
public function colorize($red, $green, $blue, $alpha = 0)
|
||||||
|
{
|
||||||
|
if (($red < -100 || $red > 100) ||
|
||||||
|
($green < -100 || $green > 100) ||
|
||||||
|
($blue < -100 || $blue > 100) ||
|
||||||
|
($alpha < -100 || $alpha > 100)) {
|
||||||
|
throw new Exception\ColorizeOutOfBoundsException(
|
||||||
|
'Colorize levels must be between -100 and +100'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// normalize colorize levels
|
||||||
|
$red = round($red * 2.55);
|
||||||
|
$green = round($green * 2.55);
|
||||||
|
$blue = round($blue * 2.55);
|
||||||
|
$alpha = round($alpha * 2.55);
|
||||||
|
|
||||||
|
// apply filter
|
||||||
|
imagefilter($this->resource, IMG_FILTER_COLORIZE, $red, $green, $blue, $alpha);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply blur filter on the current image
|
* Apply blur filter on the current image
|
||||||
*
|
*
|
||||||
|
@@ -1577,6 +1577,23 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
|||||||
$img->contrast(-101);
|
$img->contrast(-101);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testColorizeImage()
|
||||||
|
{
|
||||||
|
$img = $this->getTestImage();
|
||||||
|
$img->colorize(-100, 0, 100);
|
||||||
|
$img->colorize(100, -100, -100, 50);
|
||||||
|
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Intervention\Image\Exception\ColorizeOutOfBoundsException
|
||||||
|
*/
|
||||||
|
public function testColorizeOutOfBounds()
|
||||||
|
{
|
||||||
|
$img = $this->getTestImage();
|
||||||
|
$img->colorize(-101, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
public function testEncode()
|
public function testEncode()
|
||||||
{
|
{
|
||||||
// default encoding
|
// default encoding
|
||||||
|
Reference in New Issue
Block a user