Preserve PNG transparency/alpha during thumbnail creation. Fixes #2805 props Libertus/Otto42.

git-svn-id: http://svn.automattic.com/wordpress/trunk@6439 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2007-12-20 22:24:39 +00:00
parent 71b2207ea3
commit 92c4835150

View File

@ -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); list($image_new_width, $image_new_height) = wp_shrink_dimensions( $sourceImageWidth, $sourceImageHeight, $max_side, $max_side);
$thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height); $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 ); @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $sourceImageWidth, $sourceImageHeight );
imagedestroy( $image ); // Free up memory imagedestroy( $image ); // Free up memory