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