diff --git a/Adapter/AdapterInterface.php b/Adapter/AdapterInterface.php index c1cb170..c3ae711 100644 --- a/Adapter/AdapterInterface.php +++ b/Adapter/AdapterInterface.php @@ -252,6 +252,16 @@ public function colorize($red, $green, $blue); */ public function sepia(); + /** + * apply vignetting to the image. + * + * @param int $sharpness value in range [0, 10], smaller is sharper + * @param int $level value in range [0, 1], smaller is brighter + * + * @return $this + */ + public function vignette($sharpness=0.5, $level=0.5); + /** * Merge with another image. * diff --git a/Adapter/GD.php b/Adapter/GD.php index 21bc00c..ded1358 100644 --- a/Adapter/GD.php +++ b/Adapter/GD.php @@ -210,6 +210,37 @@ public function sepia() return $this; } + /** + * {@inheritdoc} + */ + public function vignette($sharpness=0.5, $level=0.5) + { + + $width = imagesx($this->resource); + $height = imagesy($this->resource); + + for($x = 0; $x < imagesx($this->resource); ++$x){ + for($y = 0; $y < imagesy($this->resource); ++$y){ + $index = imagecolorat($this->resource, $x, $y); + $rgb = imagecolorsforindex($this->resource, $index); + + $l = sin(M_PI / $width * $x) * sin(M_PI / $height * $y); + $l = pow($l, $sharpness); + $l = 1 - $level * (1 - $l); + + $rgb['red'] *= $l; + $rgb['green'] *= $l; + $rgb['blue'] *= $l; + + $color = imagecolorallocate($this->resource, $rgb['red'], $rgb['green'], $rgb['blue']); + + imagesetpixel($this->resource, $x, $y, $color); + } + } + + return $this; + } + /** * {@inheritdoc} */ diff --git a/Adapter/Imagick.php b/Adapter/Imagick.php index 365e0c6..63664c0 100644 --- a/Adapter/Imagick.php +++ b/Adapter/Imagick.php @@ -208,6 +208,19 @@ public function sepia() // TODO: Implement sepia() method. } + /** + * apply vignetting to the image. + * + * @param int $sharpness value in range [0, 10], smaller is sharper + * @param int $level value in range [0, 1], smaller is brighter + * + * @return $this + */ + public function vignette($sharpness=0.5, $level=0.5) + { + // TODO: Implement vignette() method. + } + /** * Merge with another image. *