1
0
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:
Oliver Vogel
2013-11-09 12:12:34 +01:00
parent 199b278c63
commit 96b84d15d8
3 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
<?php
namespace Intervention\Image\Exception;
class ColorizeOutOfBoundsException extends \OutOfBoundsException
{
# nothing to override
}

View File

@@ -1275,6 +1275,37 @@ class Image
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
*

View File

@@ -1577,6 +1577,23 @@ class ImageTest extends PHPUnit_Framework_Testcase
$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()
{
// default encoding