From 5f81e994aa6da2a9d089783ac33d1a8537316940 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 29 Jan 2024 12:23:23 +0000 Subject: [PATCH] 3.3.10 - Schedule addForm and Image upsize fixes (#2331) * Schedule : Fix 404 on addForm when displayGroupId saved in session no longer exists. xibosignage/xibo#3266 * Image : Fix usage of upsize constraint, compare requested dimensions with resize limit. --- lib/Controller/Schedule.php | 27 +++++++++++++++++++++------ lib/Widget/Image.php | 15 +++++++++++---- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/Controller/Schedule.php b/lib/Controller/Schedule.php index fc2d3c9e96..5f8bf26215 100644 --- a/lib/Controller/Schedule.php +++ b/lib/Controller/Schedule.php @@ -1,8 +1,8 @@ session->get('displayGroupIds'); + + if (!is_array($displayGroupIds)) { + $displayGroupIds = []; + } + $displayGroups = []; if (count($displayGroupIds) > 0) { foreach ($displayGroupIds as $displayGroupId) { - if ($displayGroupId == -1) + if ($displayGroupId == -1) { continue; + } - $displayGroup = $this->displayGroupFactory->getById($displayGroupId); + try { + $displayGroup = $this->displayGroupFactory->getById($displayGroupId); - if ($this->getUser()->checkViewable($displayGroup)) { - $displayGroups[] = $displayGroup; + if ($this->getUser()->checkViewable($displayGroup)) { + $displayGroups[] = $displayGroup; + } + } catch (NotFoundException $e) { + $this->getLog()->debug( + sprintf( + 'Saved filter option for displayGroupId %d that no longer exists.', + $displayGroupId + ) + ); } } } diff --git a/lib/Widget/Image.php b/lib/Widget/Image.php index d3aa443cea..7f3c2a0584 100644 --- a/lib/Widget/Image.php +++ b/lib/Widget/Image.php @@ -1,6 +1,6 @@ getCheckbox('fit') === 1; + // only use upsize constraint, if we the requested dimensions are larger than resize limit. + $resizeLimit = $this->getConfig()->getSetting('DEFAULT_RESIZE_LIMIT', 6000); + $useUpsizeConstraint = max($width, $height) > $resizeLimit; + $this->getLog()->debug('Whole file: ' . $filePath . ' requested with Width and Height ' . $width . ' x ' . $height . ', proportional: ' . var_export($proportional, true) - . ', fit: ' . var_export($fit, true)); + . ', fit: ' . var_export($fit, true) + . ', upsizeConstraint ' . var_export($useUpsizeConstraint, true)); $img = Img::make($filePath); @@ -282,11 +287,13 @@ public function download(Request $request, Response $response): Response if ($fit) { $img->fit($width, $height); } else { - $img->resize($width, $height, function ($constraint) use ($proportional) { + $img->resize($width, $height, function ($constraint) use ($proportional, $useUpsizeConstraint) { if ($proportional) { $constraint->aspectRatio(); } - $constraint->upsize(); + if ($useUpsizeConstraint) { + $constraint->upsize(); + } }); } }