2121 *
2222 * @package Web200\ImageResize\Model
2323 * @author Web200 <[email protected] > 24- * @copyright 2019 Web200
24+ * @copyright 2024 Web200
2525 * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
2626 * @link https://www.web200.fr/
2727 */
@@ -114,6 +114,7 @@ class Resize
114114 * - backgroundColor[null]: Default white
115115 */
116116 protected $ defaultSettings = [
117+ 'crop ' => true ,
117118 'constrainOnly ' => true ,
118119 'keepAspectRatio ' => true ,
119120 'keepTransparency ' => true ,
@@ -127,6 +128,7 @@ class Resize
127128 * @var string[] $subPathSettingsMapping
128129 */
129130 protected $ subPathSettingsMapping = [
131+ 'crop ' => 'cr ' ,
130132 'constrainOnly ' => 'co ' ,
131133 'keepAspectRatio ' => 'ar ' ,
132134 'keepTransparency ' => 'tr ' ,
@@ -289,6 +291,7 @@ protected function initResizeSettings(array $resizeSettings): void
289291 {
290292 // Init resize settings with default
291293 $ this ->resizeSettings = [
294+ 'crop ' => false ,
292295 'constrainOnly ' => $ this ->config ->getDefaultConstrainOnly (),
293296 'keepAspectRatio ' => $ this ->config ->getDefaultKeepAspectRatio (),
294297 'keepTransparency ' => $ this ->config ->getDefaultKeepTransparency (),
@@ -467,7 +470,13 @@ protected function resizeAndSaveImage(): bool
467470 $ imageAdapter ->keepFrame ($ this ->resizeSettings ['keepFrame ' ]);
468471 $ imageAdapter ->backgroundColor ($ this ->resizeSettings ['backgroundColor ' ]);
469472 $ imageAdapter ->quality ($ this ->resizeSettings ['quality ' ]);
470- $ imageAdapter ->resize ($ this ->width , $ this ->height );
473+
474+ if ($ this ->resizeSettings ['crop ' ] === true ) {
475+ $ imageAdapter ->resizeToSquare ($ this ->width , $ this ->height );
476+ } else {
477+ $ imageAdapter ->resize ($ this ->width , $ this ->height );
478+ }
479+
471480 $ imageAdapter ->save ($ this ->getAbsolutePathResized ());
472481
473482 return true ;
0 commit comments