Skip to content

Commit

Permalink
3.3.10 - Schedule addForm and Image upsize fixes (#2331)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
PeterMis authored Jan 29, 2024
1 parent 3095896 commit 5f81e99
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
27 changes: 21 additions & 6 deletions lib/Controller/Schedule.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -730,17 +730,32 @@ function addForm(Request $request, Response $response)
{
// Get the display groups added to the session (if there are some)
$displayGroupIds = $this->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
)
);
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions lib/Widget/Image.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -270,10 +270,15 @@ public function download(Request $request, Response $response): Response

$fit = $proportional && $sanitizedParams->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);

Expand All @@ -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();
}
});
}
}
Expand Down

0 comments on commit 5f81e99

Please sign in to comment.