Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
31 changes: 31 additions & 0 deletions Adapter/GD.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
13 changes: 13 additions & 0 deletions Adapter/Imagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down