mirror of
https://github.com/Intervention/image.git
synced 2025-08-27 23:59:50 +02:00
Added BlurModifiers
This commit is contained in:
36
src/Drivers/Gd/Modifiers/BlurModifier.php
Normal file
36
src/Drivers/Gd/Modifiers/BlurModifier.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||
|
||||
use Intervention\Image\Interfaces\FrameInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ModifierInterface;
|
||||
|
||||
class BlurModifier implements ModifierInterface
|
||||
{
|
||||
/**
|
||||
* Create new modifier
|
||||
*
|
||||
* @param int $amount Blur amount (0 - 100%)
|
||||
*/
|
||||
public function __construct(int $amount)
|
||||
{
|
||||
$this->amount = $amount;
|
||||
}
|
||||
|
||||
public function apply(ImageInterface $image): ImageInterface
|
||||
{
|
||||
foreach ($image as $frame) {
|
||||
$this->blurFrame($frame);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function blurFrame(FrameInterface $frame): void
|
||||
{
|
||||
for ($i = 0; $i < $this->amount; $i++) {
|
||||
imagefilter($frame->getCore(), IMG_FILTER_GAUSSIAN_BLUR);
|
||||
}
|
||||
}
|
||||
}
|
28
src/Drivers/Imagick/Modifiers/BlurModifier.php
Normal file
28
src/Drivers/Imagick/Modifiers/BlurModifier.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
||||
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ModifierInterface;
|
||||
|
||||
class BlurModifier implements ModifierInterface
|
||||
{
|
||||
/**
|
||||
* Create new modifier
|
||||
*
|
||||
* @param int $amount Blur amount (0 - 100%)
|
||||
*/
|
||||
public function __construct(int $amount)
|
||||
{
|
||||
$this->amount = $amount;
|
||||
}
|
||||
|
||||
public function apply(ImageInterface $image): ImageInterface
|
||||
{
|
||||
foreach ($this->image as $frame) {
|
||||
$frame->getCore()->blurImage(1 * $this->amount, 0.5 * $this->amount);
|
||||
}
|
||||
|
||||
return $this->image;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user