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 |
||
31 | 18 | public function resize(Image $image, int $maxHeight, bool $useWebp): string |
|
32 | { |
||
33 | 18 | if ($image->getMime() === 'image/svg+xml') { |
|
34 | 6 | return $image->getPath(); |
|
35 | } |
||
36 | |||
37 | 12 | $maxHeight = min($maxHeight, $image->getHeight()); |
|
38 | |||
39 | 12 | $basename = pathinfo($image->getFilename(), PATHINFO_FILENAME); |
|
40 | 12 | $extension = $useWebp ? '.webp' : '.jpg'; |
|
41 | 12 | $path = realpath('.') . '/' . self::CACHE_IMAGE_PATH . $basename . '-' . $maxHeight . $extension; |
|
|
|||
42 | |||
43 | 12 | if (file_exists($path)) { |
|
44 | return $path; |
||
45 | } |
||
46 | |||
47 | 12 | $image = $this->imagine->open($image->getPath()); |
|
48 | 12 | $image->thumbnail(new Box(1000000, $maxHeight))->save($path); |
|
49 | |||
50 | 12 | return $path; |
|
51 | } |
||
53 |