| 1 |
<?php |
| 2 |
|
| 3 |
namespace League\Glide\Manipulators; |
| 4 |
|
| 5 |
use Intervention\Image\Image; |
| 6 |
|
| 7 |
/** |
| 8 |
* @property string $pixel |
| 9 |
*/ |
| 10 |
class Pixelate extends BaseManipulator |
| 11 |
{ |
| 12 |
/** |
| 13 |
* Perform pixelate image manipulation. |
| 14 |
* |
| 15 |
* @param Image $image The source image. |
| 16 |
* |
| 17 |
* @return Image The manipulated image. |
| 18 |
*/ |
| 19 |
public function run(Image $image) |
| 20 |
{ |
| 21 |
$pixelate = $this->getPixelate(); |
| 22 |
|
| 23 |
if (null !== $pixelate) { |
| 24 |
$image->pixelate($pixelate); |
| 25 |
} |
| 26 |
|
| 27 |
return $image; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Resolve pixelate amount. |
| 32 |
* |
| 33 |
* @return int|null The resolved pixelate amount. |
| 34 |
*/ |
| 35 |
public function getPixelate() |
| 36 |
{ |
| 37 |
if (!is_numeric($this->pixel)) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
if ($this->pixel < 0 or $this->pixel > 1000) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
return (int) $this->pixel; |
| 46 |
} |
| 47 |
} |
| 48 |
|