From 1d161bb26e14666bea2100429194c38c817a377d Mon Sep 17 00:00:00 2001 From: thisgun Date: Fri, 22 Dec 2017 11:39:17 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8D=B8=EB=84=A4=EC=9D=BC=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/default.config.php | 3 ++ lib/thumbnail.lib.php | 87 +++++++++++++++++++++++++++------------ 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/extend/default.config.php b/extend/default.config.php index 8337baa2b..8bde033a9 100644 --- a/extend/default.config.php +++ b/extend/default.config.php @@ -3,4 +3,7 @@ if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가 // 유저 사이드뷰에서 아이콘 지정 안했을시 기본 no 프로필 이미지 define('G5_NO_PROFILE_IMG', 'no_profile'); + +// 썸네일 처리 방식, 비율유지 하지 않고 썸네일을 생성하려면 주석을 풀고 값은 false 입력합니다. ( true 또는 주석으로 된 경우에는 비율 유지합니다. ) +//define('G5_USE_THUMB_RATIO', false); ?> \ No newline at end of file diff --git a/lib/thumbnail.lib.php b/lib/thumbnail.lib.php index 3f6c20866..1665d207a 100644 --- a/lib/thumbnail.lib.php +++ b/lib/thumbnail.lib.php @@ -349,14 +349,17 @@ function thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_h } else { // 비율에 맞게 생성 $dst = imagecreatetruecolor($dst_w, $dst_h); $bgcolor = imagecolorallocate($dst, 255, 255, 255); // 배경색 - if($src_w > $src_h) { - $tmp_h = round(($dst_w * $src_h) / $src_w); - $dst_y = round(($dst_h - $tmp_h) / 2); - $dst_h = $tmp_h; - } else { - $tmp_w = round(($dst_h * $src_w) / $src_h); - $dst_x = round(($dst_w - $tmp_w) / 2); - $dst_w = $tmp_w; + + if ( !((defined('G5_USE_THUMB_RATIO') && false === G5_USE_THUMB_RATIO) || (defined('G5_THEME_USE_THUMB_RATIO') && false === G5_THEME_USE_THUMB_RATIO)) ){ + if($src_w > $src_h) { + $tmp_h = round(($dst_w * $src_h) / $src_w); + $dst_y = round(($dst_h - $tmp_h) / 2); + $dst_h = $tmp_h; + } else { + $tmp_w = round(($dst_h * $src_w) / $src_h); + $dst_x = round(($dst_w - $tmp_w) / 2); + $dst_w = $tmp_w; + } } if($size[2] == 3) { @@ -382,34 +385,64 @@ function thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_h $dst = imagecreatetruecolor($dst_w, $dst_h); $bgcolor = imagecolorallocate($dst, 255, 255, 255); // 배경색 - if($src_w < $dst_w) { - if($src_h >= $dst_h) { - if( $src_h > $src_w ){ - $tmp_w = round(($dst_h * $src_w) / $src_h); - $dst_x = round(($dst_w - $tmp_w) / 2); - $dst_w = $tmp_w; - } else { + if ( ((defined('G5_USE_THUMB_RATIO') && false === G5_USE_THUMB_RATIO) || (defined('G5_THEME_USE_THUMB_RATIO') && false === G5_THEME_USE_THUMB_RATIO)) ){ + //이미지 썸네일을 비율 유지하지 않습니다. (5.2.6 버전 이하에서 처리된 부분과 같음) + + if($src_w < $dst_w) { + if($src_h >= $dst_h) { $dst_x = round(($dst_w - $src_w) / 2); $src_h = $dst_h; + if( $dst_w > $src_w ){ + $dst_w = $src_w; + } + } else { + $dst_x = round(($dst_w - $src_w) / 2); + $dst_y = round(($dst_h - $src_h) / 2); + $dst_w = $src_w; + $dst_h = $src_h; } } else { - $dst_x = round(($dst_w - $src_w) / 2); - $dst_y = round(($dst_h - $src_h) / 2); - $dst_w = $src_w; - $dst_h = $src_h; - } - } else { - if($src_h < $dst_h) { - if( $src_w > $dst_w ){ - $tmp_h = round(($dst_w * $src_h) / $src_w); - $dst_y = round(($dst_h - $tmp_h) / 2); - $dst_h = $tmp_h; - } else { + if($src_h < $dst_h) { $dst_y = round(($dst_h - $src_h) / 2); $dst_h = $src_h; $src_w = $dst_w; } } + + } else { + //이미지 썸네일을 비율 유지하며 썸네일 생성합니다. + if($src_w < $dst_w) { + if($src_h >= $dst_h) { + if( $src_h > $src_w ){ + $tmp_w = round(($dst_h * $src_w) / $src_h); + $dst_x = round(($dst_w - $tmp_w) / 2); + $dst_w = $tmp_w; + } else { + $dst_x = round(($dst_w - $src_w) / 2); + $src_h = $dst_h; + if( $dst_w > $src_w ){ + $dst_w = $src_w; + } + } + } else { + $dst_x = round(($dst_w - $src_w) / 2); + $dst_y = round(($dst_h - $src_h) / 2); + $dst_w = $src_w; + $dst_h = $src_h; + } + } else { + if($src_h < $dst_h) { + if( $src_w > $dst_w ){ + $tmp_h = round(($dst_w * $src_h) / $src_w); + $dst_y = round(($dst_h - $tmp_h) / 2); + $dst_h = $tmp_h; + } else { + $dst_y = round(($dst_h - $src_h) / 2); + $dst_h = $src_h; + $src_w = $dst_w; + } + } + } } if($size[2] == 3) {