| Conditions | 5 |
| Paths | 5 |
| Total Lines | 18 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 5.0187 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 31 | 12 | public function resize(Image $image, int $maxHeight, bool $useWebp): string |
|
| 32 | { |
||
| 33 | 12 | if ($image->getHeight() <= $maxHeight || $image->getMime() === 'image/svg+xml') { |
|
| 34 | 10 | return $image->getPath(); |
|
| 35 | } |
||
| 36 | |||
| 37 | 2 | $basename = pathinfo($image->getFilename(), PATHINFO_FILENAME); |
|
| 38 | 2 | $extension = $useWebp ? '.webp' : '.jpg'; |
|
| 39 | 2 | $path = realpath('.') . '/' . self::CACHE_IMAGE_PATH . $basename . '-' . $maxHeight . $extension; |
|
| 40 | |||
| 41 | 2 | if (file_exists($path)) { |
|
| 42 | return $path; |
||
| 43 | } |
||
| 44 | |||
| 45 | 2 | $image = $this->imagine->open($image->getPath()); |
|
| 46 | 2 | $image->thumbnail(new Box(1000000, $maxHeight))->save($path); |
|
| 47 | |||
| 48 | 2 | return $path; |
|
| 49 | } |
||
| 51 |