| Conditions | 4 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | public function execute(Image $image) |
||
| 28 | { |
||
| 29 | $level = $this->options->getLevel(); |
||
|
|
|||
| 30 | if (!$level) { |
||
| 31 | return $image; |
||
| 32 | } |
||
| 33 | |||
| 34 | $resource = $image->getResource(); |
||
| 35 | |||
| 36 | // start from the top-left pixel and keep looping until we have the desired effect |
||
| 37 | for ($y = 0;$y < $image->getHeight();$y += $level + 1) { |
||
| 38 | for ($x = 0;$x < $image->getWidth();$x += $level + 1) { |
||
| 39 | // get the color for current pixel |
||
| 40 | $rgb = imagecolorsforindex($resource, imagecolorat($resource, $x, $y)); |
||
| 41 | |||
| 42 | // get the closest color from palette |
||
| 43 | $color = imagecolorclosest($resource, $rgb['red'], $rgb['green'], $rgb['blue']); |
||
| 44 | imagefilledrectangle($resource, $x, $y, $x + $level, $y + $level, $color); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | return $image; |
||
| 49 | } |
||
| 51 |