@@ -76,7 +76,7 @@ public static function getModuleInfo(): array
7676 {
7777 return [
7878 'title ' => __ ('Intervention Image Engine ' ),
79- 'version ' => 7 ,
79+ 'version ' => 8 ,
8080 'summary ' => __ ('Replaces PW sizing with Intervention Image + Delayed Rendering using ImageManager logic. ' ),
8181 'author ' => 'Iskender TOTOGLU @trk @ukyo ' ,
8282 'href ' => 'https://github.com/trk/InterventionImage ' ,
@@ -259,7 +259,7 @@ protected function parseAndSetupConfigs(): void
259259
260260 foreach ($ aspectRatios ['data ' ] as $ key => $ ratio ) {
261261 foreach ($ columnWidths as $ columnWidth ) {
262- list ( $ n , $ d) = explode ('- ' , $ columnWidth );
262+ [ $ n , $ d] = explode ('- ' , $ columnWidth );
263263 $ width = (int ) ceil ($ breakpoints ['default ' ]['value ' ] * ($ n / $ d ));
264264
265265 $ dimensions = $ this ->calculate ($ width , null , $ key );
@@ -287,9 +287,9 @@ protected function multilineConfigToArray(string $str): array
287287 $ conf = ['value ' => null , 'key ' => null , 'label ' => null ];
288288
289289 if (str_contains ($ line , '= ' )) {
290- list ( $ conf ['value ' ], $ rest) = explode ('= ' , $ line );
290+ [ $ conf ['value ' ], $ rest] = array_pad ( explode ('= ' , $ line, 2 ), 2 , '' );
291291 if (str_contains ($ rest , '| ' )) {
292- list ( $ conf ['key ' ], $ conf ['label ' ]) = explode ('| ' , $ rest );
292+ [ $ conf ['key ' ], $ conf ['label ' ]] = array_pad ( explode ('| ' , $ rest, 2 ), 2 , '' );
293293 } else {
294294 $ conf ['key ' ] = $ rest ;
295295 $ conf ['label ' ] = $ rest ;
@@ -410,9 +410,13 @@ protected function resolveParameters(Pageimage $image, int|string|null $width, i
410410 if (!is_int ($ width )) $ width = 0 ;
411411
412412 if ($ width > 0 && $ height === 0 ) {
413- $ height = (int ) round ($ width * ($ image ->height / $ image ->width ));
413+ $ iw = max (1 , $ image ->width );
414+ $ ih = max (1 , $ image ->height );
415+ $ height = (int ) round ($ width * ($ ih / $ iw ));
414416 } elseif ($ height > 0 && $ width === 0 ) {
415- $ width = (int ) round ($ height / ($ image ->height / $ image ->width ));
417+ $ iw = max (1 , $ image ->width );
418+ $ ih = max (1 , $ image ->height );
419+ $ width = (int ) round ($ height / ($ ih / $ iw ));
416420 }
417421
418422 if (!empty ($ options ['insert ' ])) {
@@ -532,7 +536,7 @@ public function hookSize(HookEvent $event)
532536 $ config = $ this ->wire ()->config ;
533537 $ image = $ event ->object ;
534538
535- if ($ image ->ext === ' svg ' ) {
539+ if (strcasecmp ( $ image ->ext , ' svg ' ) === 0 || $ image -> mime () === ' image/ svg+xml ' ) {
536540 $ event ->return = $ image ;
537541 return ;
538542 }
@@ -663,15 +667,15 @@ public function hookAttrs(HookEvent $event)
663667
664668 $ sources = [];
665669 // AVIF Source
666- if (in_array ( ' avifAdd ' , $ this ->options ) && $ source ->ext !== 'avif ' ) {
670+ if ($ this ->avifAdd && $ source ->ext !== 'avif ' ) {
667671 $ sources [] = [
668672 'type ' => 'image/avif ' ,
669673 'srcset ' => $ image ->srcset (null , array_merge ($ srcsetOptions , ['format ' => 'avif ' ]))
670674 ];
671675 }
672676
673677 // WebP Source
674- if (in_array ( ' webpAdd ' , $ this ->options ) && $ source ->ext !== 'webp ' ) {
678+ if ($ this ->webpAdd && $ source ->ext !== 'webp ' ) {
675679 $ webpSrcset = $ image ->srcset (null , array_merge ($ srcsetOptions , ['format ' => 'webp ' ]));
676680 $ sources [] = [
677681 'type ' => 'image/webp ' ,
@@ -831,16 +835,28 @@ public function handlePageNotFound(HookEvent $event)
831835 /**
832836 * Hook: Deletes variation files when original image is deleted
833837 *
834- * @param HookEvent $event
838+ * @param HookEvent $e
835839 */
836840 public function hookDeleteVariations (HookEvent $ e )
837841 {
838842 if (!$ e ->object instanceof Pageimage) return ;
839843 $ pi = pathinfo ($ e ->object ->filename );
840- $ files = glob ($ pi ['dirname ' ] . '/ ' . $ pi ['filename ' ] . '.* ' );
841- if ($ files ) {
842- foreach ($ files as $ f ) {
843- if ($ f !== $ e ->object ->filename ) @unlink ($ f );
844+ $ prefix = $ pi ['filename ' ] . '. ' ;
845+ $ dir = $ pi ['dirname ' ];
846+
847+ if (!is_dir ($ dir )) return ;
848+
849+ try {
850+ $ it = new \FilesystemIterator ($ dir , \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME );
851+ foreach ($ it as $ path ) {
852+ $ base = basename ($ path );
853+ if (str_starts_with ($ base , $ prefix ) && $ path !== $ e ->object ->filename ) {
854+ $ this ->wire ()->files ->unlink ($ path );
855+ }
856+ }
857+ } catch (\Exception $ ex ) {
858+ if ($ this ->wire ()->config ->debug ) {
859+ $ this ->wire ()->log ->warning ("InterventionImage variation delete warning: " . $ ex ->getMessage ());
844860 }
845861 }
846862 }
@@ -890,7 +906,7 @@ protected function generateLqip(Pageimage $image): string
890906 *
891907 * @return Pageimage|EncodedImage Returns Pageimage for hooks, EncodedImage for direct output
892908 */
893- protected function create ($ source , string $ destination , int $ width = 0 , int $ height = 0 , array $ options = [])
909+ protected function create (Pageimage | string $ source , string $ destination , int $ width = 0 , int $ height = 0 , array $ options = []): Pageimage | EncodedImage
894910 {
895911 $ filename = ($ source instanceof Pageimage) ? $ source ->filename : $ source ;
896912
@@ -1164,15 +1180,9 @@ protected function createSuffix(array $params): string
11641180 // Flop (e.g. -flop)
11651181 if (!empty ($ options ['flop ' ])) $ parts [] = 'flop ' ;
11661182
1167- // Flip (e.g. -flip)
1168- // if (!empty($options['flip'])) $parts[] = 'flip';
1169-
11701183 // Blur (e.g. -blu10)
11711184 if (!empty ($ options ['blur ' ])) $ parts [] = 'blu ' . (int ) $ options ['blur ' ];
11721185
1173- // Rotate (e.g. -rot10)
1174- // if (!empty($options['rotate'])) $parts[] = 'rot' . (int) $options['rotate'];
1175-
11761186 // Sharpen (e.g. -sha10)
11771187 if (!empty ($ options ['sharpen ' ])) $ parts [] = 'sha ' . (int ) $ options ['sharpen ' ];
11781188
0 commit comments