From 633bc340e7008ef15cab33f41882597838ea82ec Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sat, 19 Jun 2021 23:11:59 +0900 Subject: [PATCH] Fix #1707 support thumbnail height value of 'auto' in any type --- classes/file/FileHandler.class.php | 8 +++++++- modules/comment/comment.item.php | 8 ++++---- modules/document/document.item.php | 10 +++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/classes/file/FileHandler.class.php b/classes/file/FileHandler.class.php index ee65e97e1..eb096b37f 100644 --- a/classes/file/FileHandler.class.php +++ b/classes/file/FileHandler.class.php @@ -543,7 +543,13 @@ class FileHandler { $target_type = 'jpg'; } - + + // Automatically set resize_height if it is 'auto' + if ($resize_height === 'auto') + { + $resize_height = round($resize_width / ($width / $height)); + } + // create temporary image having original type if ($type === 'gif' && function_exists('imagecreatefromgif')) { diff --git a/modules/comment/comment.item.php b/modules/comment/comment.item.php index aaa37f9fd..6abee29e7 100644 --- a/modules/comment/comment.item.php +++ b/modules/comment/comment.item.php @@ -698,7 +698,7 @@ class commentItem extends BaseObject } // If signiture height setting is omitted, create a square - if(!$height) + if(!$height || (!ctype_digit($height) && $height !== 'auto')) { $height = $width; } @@ -707,7 +707,7 @@ class commentItem extends BaseObject $thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->comment_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type); - $thumbnail_url = Context::getRequestUri() . $thumbnail_file; + $thumbnail_url = RX_BASEURL . $thumbnail_file; $thumbnail_file = RX_BASEDIR . $thumbnail_file; // return false if a size of existing thumbnail file is 0. otherwise return the file path @@ -762,7 +762,7 @@ class commentItem extends BaseObject if($file->cover_image === 'Y' && file_exists($file->uploaded_filename)) { - $source_file = $file->uploaded_filename; + $source_file = FileHandler::getRealPath($file->uploaded_filename); break; } @@ -779,7 +779,7 @@ class commentItem extends BaseObject if(!$source_file && $first_image) { - $source_file = $first_image; + $source_file = FileHandler::getRealPath($first_image); } } diff --git a/modules/document/document.item.php b/modules/document/document.item.php index 873697680..051b07279 100644 --- a/modules/document/document.item.php +++ b/modules/document/document.item.php @@ -1082,7 +1082,7 @@ class documentItem extends BaseObject } // If not specify its height, create a square - if(!$height) + if(!$height || (!ctype_digit($height) && $height !== 'auto')) { $height = $width; } @@ -1091,7 +1091,7 @@ class documentItem extends BaseObject $thumbnail_path = sprintf('files/thumbnails/%s',getNumberingPath($this->document_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type); - $thumbnail_url = Context::getRequestUri().$thumbnail_file; + $thumbnail_url = RX_BASEURL . $thumbnail_file; $thumbnail_file = RX_BASEDIR . $thumbnail_file; // Return false if thumbnail file exists and its size is 0. Otherwise, return its path @@ -1166,7 +1166,7 @@ class documentItem extends BaseObject } if($file->cover_image === 'Y') { - $source_file = $file->uploaded_filename; + $source_file = FileHandler::getRealPath($file->uploaded_filename); break; } if(!$first_image) @@ -1176,7 +1176,7 @@ class documentItem extends BaseObject } if(!$source_file && $first_image) { - $source_file = $first_image; + $source_file = FileHandler::getRealPath($first_image); } } @@ -1229,7 +1229,7 @@ class documentItem extends BaseObject } } } - + if($source_file) { $output_file = FileHandler::createImageFile($source_file, $thumbnail_file, $trigger_obj->width, $trigger_obj->height, $trigger_obj->image_type, $trigger_obj->type, $trigger_obj->quality);