From c72e24c0c7a7ec49fcac51c1a9dc990799411b97 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Wed, 30 Dec 2020 15:34:55 +0100 Subject: [PATCH] EditAsset: refactor common expression into its own variable. --- controllers/EditAsset.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/controllers/EditAsset.php b/controllers/EditAsset.php index 3b99a52..8fc7bf4 100644 --- a/controllers/EditAsset.php +++ b/controllers/EditAsset.php @@ -116,20 +116,22 @@ class EditAsset extends HTMLController if (!preg_match('~^(?\d+)x(?\d+)(?_c(?[best]?))?$~', $selector, $thumb)) continue; + $dimensions = $thumb['width'] . 'x' . $thumb['height']; + // Does the thumbnail exist on disk? If not, use an url to generate it. if (!$filename || !file_exists(THUMBSDIR . '/' . $subdir . '/' . $filename)) - $thumb_url = BASEURL . '/thumbnail/' . $image->getId() . '/' . $thumb['width'] . 'x' . $thumb['height'] . ($thumb['suffix'] ?? '') . '/'; + $thumb_url = BASEURL . '/thumbnail/' . $image->getId() . '/' . $dimensions . ($thumb['suffix'] ?? '') . '/'; else $thumb_url = THUMBSURL . '/' . $subdir . '/' . $filename; - $has_crop_boundary = isset($metadata['crop_' . $thumb['width'] . 'x' . $thumb['height']]); - $has_custom_image = isset($metadata['custom_' . $thumb['width'] . 'x' . $thumb['height']]); + $has_crop_boundary = isset($metadata['crop_' . $dimensions]); + $has_custom_image = isset($metadata['custom_' . $dimensions]); $thumbs[] = [ 'dimensions' => [(int) $thumb['width'], (int) $thumb['height']], 'cropped' => !$has_custom_image && (!empty($thumb['suffix']) || $has_crop_boundary), 'crop_method' => !$has_custom_image && !empty($thumb['method']) ? $thumb['method'] : (!empty($thumb['suffix']) ? 'c' : null), - 'crop_region' => $has_crop_boundary ? $metadata['crop_' . $thumb['width'] . 'x' . $thumb['height']] : null, + 'crop_region' => $has_crop_boundary ? $metadata['crop_' . $dimensions] : null, 'custom_image' => $has_custom_image, 'filename' => $filename, 'url' => $thumb_url,