Skip to content

Commit d87990a

Browse files
travisrisnerQuyTonrichard67
authored
[5.3] - Respect individual width/height constraints in Media Action - Resize plugin (joomla#45311)
Fix issue joomla#44862 in the Media Action - Resize plugin where images are resized unnecessarily when only one dimension (width or height) is set. The logic has been updated to evaluate width and height independently. The plugin now only resizes if the image exceeds a defined constraint. --------- Co-authored-by: Quy Ton <[email protected]> Co-authored-by: Richard Fath <[email protected]>
1 parent 274cd3a commit d87990a

File tree

1 file changed

+8
-3
lines changed
  • plugins/media-action/resize/src/Extension

1 file changed

+8
-3
lines changed

plugins/media-action/resize/src/Extension/Resize.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,18 @@ public function onContentBeforeSave(BeforeSaveEvent $event): void
7272

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

75-
if ($imgObject->getWidth() < $this->params->get('batch_width', 0) && $imgObject->getHeight() < $this->params->get('batch_height', 0)) {
75+
$maxWidth = (int) $this->params->get('batch_width', 0);
76+
$maxHeight = (int) $this->params->get('batch_height', 0);
77+
if (
78+
!(($maxWidth && $imgObject->getWidth() > $maxWidth)
79+
|| ($maxHeight && $imgObject->getHeight() > $maxHeight))
80+
) {
7681
return;
7782
}
7883

7984
$imgObject->resize(
80-
$this->params->get('batch_width', 0),
81-
$this->params->get('batch_height', 0),
85+
$maxWidth,
86+
$maxHeight,
8287
false,
8388
Image::SCALE_INSIDE
8489
);

0 commit comments

Comments
 (0)