From 4a65c03ee7a60fe839c9d17c45480d67fc96bddb Mon Sep 17 00:00:00 2001 From: Rizlation Date: Sat, 26 Jul 2014 15:52:06 -0500 Subject: [PATCH 1/2] Update functions.php Changed createThumbnail() to support transparent PNG thumbnails. --- inc/functions.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 7882b73..9c4b4cc 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -362,9 +362,19 @@ function createThumbnail($name, $filename, $new_w, $new_h) { $thumb_w = round($old_x * $percent); $thumb_h = round($old_y * $percent); - $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); - fastImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); + if (preg_match("/png/", $system[0]) && (imagepng($src_img, $filename))) { + $dst_img = imagecreatetruecolor($thumb_w, $thumb_h); + imagealphablending($dst_img, false); + imagesavealpha($dst_img, true); + $color = imagecolorallocatealpha($dst_img, 0, 0, 0, 0); + imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $color); + imagecolortransparent($dst_img, $color); + } else { + $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); + } + ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); + if (preg_match("/png/", $system[0])) { if (!imagepng($dst_img, $filename)) { return false; @@ -378,10 +388,10 @@ function createThumbnail($name, $filename, $new_w, $new_h) { return false; } } - + imagedestroy($dst_img); imagedestroy($src_img); - + return true; } From cfe4ca8b6bdb8f392900d69dbdbba3f30afd1693 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Sun, 3 Aug 2014 13:43:33 -0700 Subject: [PATCH 2/2] Minor thumbnail function tweaks --- inc/functions.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 9c4b4cc..33ec6fc 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -362,19 +362,20 @@ function createThumbnail($name, $filename, $new_w, $new_h) { $thumb_w = round($old_x * $percent); $thumb_h = round($old_y * $percent); - if (preg_match("/png/", $system[0]) && (imagepng($src_img, $filename))) { - $dst_img = imagecreatetruecolor($thumb_w, $thumb_h); + $dst_img = imagecreatetruecolor($thumb_w, $thumb_h); + if (preg_match("/png/", $system[0]) && imagepng($src_img, $filename)) { imagealphablending($dst_img, false); imagesavealpha($dst_img, true); + $color = imagecolorallocatealpha($dst_img, 0, 0, 0, 0); imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $color); imagecolortransparent($dst_img, $color); - } else { - $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); + + imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); + } else { + fastimagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); } - ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); - if (preg_match("/png/", $system[0])) { if (!imagepng($dst_img, $filename)) { return false; @@ -388,14 +389,14 @@ function createThumbnail($name, $filename, $new_w, $new_h) { return false; } } - + imagedestroy($dst_img); imagedestroy($src_img); - + return true; } -function fastImageCopyResampled(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) { +function fastimagecopyresampled(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) { // Author: Tim Eckel - Date: 12/17/04 - Project: FreeRingers.net - Freely distributable. if (empty($src_image) || empty($dst_image)) { return false;