Skip to content
11 changes: 8 additions & 3 deletions plugins/media-action/resize/src/Extension/Resize.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ public function onContentBeforeSave(BeforeSaveEvent $event): void

$imgObject = new Image(imagecreatefromstring($item->data));

if ($imgObject->getWidth() < $this->params->get('batch_width', 0) && $imgObject->getHeight() < $this->params->get('batch_height', 0)) {
$maxWidth = (int) $this->params->get('batch_width', 0);
$maxHeight = (int) $this->params->get('batch_height', 0);
if (
!(($maxWidth && $imgObject->getWidth() > $maxWidth)
|| ($maxHeight && $imgObject->getHeight() > $maxHeight))
) {
return;
}

$imgObject->resize(
$this->params->get('batch_width', 0),
$this->params->get('batch_height', 0),
$maxWidth,
$maxHeight,
false,
Image::SCALE_INSIDE
);
Expand Down