@@ -631,17 +631,7 @@ public function resizeFile($source, $keepRatio = true)
631631
632632 $ image ->keepAspectRatio ($ keepRatio );
633633
634- list ($ imageWidth , $ imageHeight ) = @getimagesize ($ source );
635-
636- if ($ imageWidth && $ imageHeight ) {
637- $ configWidth = $ this ->_resizeParameters ['width ' ];
638- $ configHeight = $ this ->_resizeParameters ['height ' ];
639- $ imageWidth = $ configWidth > $ imageWidth ? $ imageWidth : $ configWidth ;
640- $ imageHeight = $ configHeight > $ imageHeight ? $ imageHeight : $ configHeight ;
641- } else {
642- $ imageWidth = $ this ->_resizeParameters ['width ' ];
643- $ imageHeight = $ this ->_resizeParameters ['height ' ];
644- }
634+ list ($ imageWidth , $ imageHeight ) = $ this ->getResizedParams ($ source );
645635
646636 $ image ->resize ($ imageWidth , $ imageHeight );
647637 $ dest = $ targetDir . '/ ' . $ this ->ioFile ->getPathInfo ($ source )['basename ' ];
@@ -652,6 +642,29 @@ public function resizeFile($source, $keepRatio = true)
652642 return false ;
653643 }
654644
645+ /**
646+ * Return width height for the image resizing.
647+ *
648+ * @param string $source
649+ */
650+ private function getResizedParams (string $ source ): array
651+ {
652+ $ configWidth = $ this ->_resizeParameters ['width ' ];
653+ $ configHeight = $ this ->_resizeParameters ['height ' ];
654+
655+ //phpcs:ignore Generic.PHP.NoSilencedErrors
656+ list ($ imageWidth , $ imageHeight ) = @getimagesize ($ source );
657+
658+ if ($ imageWidth && $ imageHeight ) {
659+ $ imageWidth = $ configWidth > $ imageWidth ? $ imageWidth : $ configWidth ;
660+ $ imageHeight = $ configHeight > $ imageHeight ? $ imageHeight : $ configHeight ;
661+ } else {
662+ return [$ configWidth , $ configHeight ];
663+ }
664+
665+ return [$ imageWidth , $ imageHeight ];
666+ }
667+
655668 /**
656669 * Resize images on the fly in controller action
657670 *
0 commit comments