|
27 | 27 |
|
28 | 28 | final class Resize implements ModifierApplicatorInterface |
29 | 29 | { |
30 | | - public function apply(Image $image, PathInfoInterface $pathInfo, ModifierValues $values, ConfigInterface $config): ?Image |
| 30 | + public function apply(Image $image, PathInfoInterface $pathInfo, ModifierValues $values, ConfigInterface $config): iterable |
31 | 31 | { |
32 | 32 | $width = $values->getOptional(Width::class); |
33 | 33 | $height = $values->getOptional(Height::class); |
@@ -70,28 +70,24 @@ public function apply(Image $image, PathInfoInterface $pathInfo, ModifierValues |
70 | 70 | $height = (int) ($height * $pd); |
71 | 71 |
|
72 | 72 | if ($width === $imageWidth && $height === $imageHeight) { |
73 | | - return null; |
| 73 | + return; |
74 | 74 | } |
75 | 75 |
|
76 | | - switch ($fit) { |
77 | | - case Fit::CONTAIN: |
78 | | - return $image->resize($width, $height, static function (Constraint $constraint) { |
79 | | - $constraint->aspectRatio(); |
80 | | - }); |
81 | | - |
82 | | - case Fit::STRETCH: |
83 | | - return $image->resize($width, $height); |
84 | | - case Fit::FILL: |
85 | | - return $image->resize($width, $height, static function (Constraint $constraint) { |
86 | | - $constraint->aspectRatio(); |
87 | | - $constraint->upsize(); |
88 | | - })->resizeCanvas($width, $height, 'center'); |
89 | | - } |
90 | | - |
91 | | - if (0 === strncmp($fit, 'crop-', 5)) { |
92 | | - $fit = substr($fit, 5); |
93 | | - } |
94 | | - |
95 | | - return $image->fit($width, $height, null, $fit); |
| 76 | + yield self::OutImage => match ($fit) { |
| 77 | + Fit::CONTAIN => $image->resize($width, $height, static function (Constraint $constraint) { |
| 78 | + $constraint->aspectRatio(); |
| 79 | + }), |
| 80 | + Fit::STRETCH => $image->resize($width, $height), |
| 81 | + Fit::FILL => $image->resize($width, $height, static function (Constraint $constraint) { |
| 82 | + $constraint->aspectRatio(); |
| 83 | + $constraint->upsize(); |
| 84 | + })->resizeCanvas($width, $height, 'center'), |
| 85 | + default => $image->fit( |
| 86 | + $width, |
| 87 | + $height, |
| 88 | + null, |
| 89 | + 0 === strncmp($fit, 'crop-', 5) ? substr($fit, 5) : $fit, |
| 90 | + ), |
| 91 | + }; |
96 | 92 | } |
97 | 93 | } |
0 commit comments