From 6a0ae6a9ed36148017e1254e529125779caf6c77 Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Thu, 20 Dec 2007 22:24:39 +0000 Subject: [PATCH] Preserve PNG transparency/alpha during thumbnail creation. Fixes #2805 props Libertus/Otto42. git-svn-id: https://develop.svn.wordpress.org/trunk@6439 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/image.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php index 5b08eef024..7bcd38ee84 100644 --- a/wp-admin/includes/image.php +++ b/wp-admin/includes/image.php @@ -33,6 +33,13 @@ function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) { list($image_new_width, $image_new_height) = wp_shrink_dimensions( $sourceImageWidth, $sourceImageHeight, $max_side, $max_side); $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height); + + // preserve PNG transparency + if( IMAGETYPE_PNG == $sourceImageType && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' )) { + imagealphablending($thumbnail, false); + imagesavealpha($thumbnail,true); + } + @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $sourceImageWidth, $sourceImageHeight ); imagedestroy( $image ); // Free up memory