From 0329ddb35bb41e5ad3bac91be5547bd27cbe45d7 Mon Sep 17 00:00:00 2001 From: Ivy Date: Sun, 3 Apr 2016 09:44:03 +0900 Subject: [PATCH 1/2] [fix] PNG image transparency can't be preserved --- system/classes/upload.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/classes/upload.class.php b/system/classes/upload.class.php index 2088fbd83..7c99b779d 100644 --- a/system/classes/upload.class.php +++ b/system/classes/upload.class.php @@ -700,7 +700,8 @@ function _copyFile() $image_dest = @imagecreatefromjpeg ($filename); unlink ($filename); } - + imagealphablending( $image_dest, false ); + imagesavealpha( $image_dest, true ); imagecopyresampled($image_dest, $image_source, 0, 0, 0, 0, $newwidth, $newheight, $imageInfo['width'], $imageInfo['height']); From 1a82c113dfd777cbecb626175812a0533de07900 Mon Sep 17 00:00:00 2001 From: Kenji ITO Date: Sun, 3 Apr 2016 10:12:29 +0900 Subject: [PATCH 2/2] Added additional check so we can use imagealphablending() and imagesavealpha() functions --- system/classes/upload.class.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/system/classes/upload.class.php b/system/classes/upload.class.php index 7c99b779d..ba39d953d 100644 --- a/system/classes/upload.class.php +++ b/system/classes/upload.class.php @@ -700,8 +700,13 @@ function _copyFile() $image_dest = @imagecreatefromjpeg ($filename); unlink ($filename); } - imagealphablending( $image_dest, false ); - imagesavealpha( $image_dest, true ); + + // Prevent transparent area of a JPEG image from being painted black + if (is_callable('imagealphablending') && is_callable('imagesavealpha')) { + imagealphablending($image_dest, false); + imagesavealpha($image_dest, true); + } + imagecopyresampled($image_dest, $image_source, 0, 0, 0, 0, $newwidth, $newheight, $imageInfo['width'], $imageInfo['height']); @@ -1344,5 +1349,3 @@ function uploadFiles() } } } - -?>