From 3351a363e810f11e1cc20b402a0174b3eb12aba9 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 23 Aug 2007 18:28:21 +0000 Subject: [PATCH] * Resizing transparent GIF images with GD now retains transparency by skipping resampling --- RELEASE-NOTES | 7 +++++-- includes/media/Bitmap.php | 29 +++++++++++++++++++---------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 12ba6a70be..978eb26938 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -398,8 +398,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 8737) Fix warnings caused by incorrect use of `/dev/null` when piping process error output under Windows * (bug 7890) Don't list redirects to special pages in Special:BrokenRedirects -* (bug 10783) Resizing PNG-24 images causes all alpha channel transparency to be - lost and transparent pixels to be turned black +* (bug 10783) Resizing PNG-24 images with GD no longer causes all alpha + channel transparency to be lost and transparent pixels to be turned black * (bug 9339) General error pages were transforming messages and their parameters in the wrong order * (bug 9026) Incorrect heading numbering when viewing Special:Statistics with @@ -407,6 +407,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Fixed invalid XHTML in Special:Upload * (bug 11013) Make sure dl() is available before attempting to use it to check available databases in installer +* Resizing transparent GIF images with GD now retains transparency by skipping + resampling + == API changes since 1.10 == diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index c43e571c1a..245abb8ccc 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -157,7 +157,7 @@ class BitmapHandler extends ImageHandler { wfDebug( "$err\n" ); return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, $err ); } - list( $loader, /* $colorStyle */, $saveType ) = $typemap[$mimeType]; + list( $loader, $colorStyle, $saveType ) = $typemap[$mimeType]; if( !function_exists( $loader ) ) { $err = "Incomplete GD library configuration: missing function $loader"; @@ -168,16 +168,25 @@ class BitmapHandler extends ImageHandler { $src_image = call_user_func( $loader, $srcPath ); $dst_image = imagecreatetruecolor( $physicalWidth, $physicalHeight ); - //PNG-24 Alpha Trans - $background = imagecolorallocate($dst_image, 0, 0, 0); //Make $dst_image all black - ImageColorTransparent($dst_image, $background); //Make $dst_image transparent - imagealphablending($dst_image, false); - - imagecopyresampled( $dst_image, $src_image, - 0,0,0,0, - $physicalWidth, $physicalHeight, imagesx( $src_image ), imagesy( $src_image ) ); + // Initialise the destination image to transparent instead of + // the default solid black, to support PNG and GIF transparency nicely + $background = imagecolorallocate( $dst_image, 0, 0, 0 ); + imagecolortransparent( $dst_image, $background ); + imagealphablending( $dst_image, false ); + + if( $colorStyle == 'palette' ) { + // Don't resample for paletted GIF images. + // It may just uglify them, and completely breaks transparency. + imagecopyresized( $dst_image, $src_image, + 0,0,0,0, + $physicalWidth, $physicalHeight, imagesx( $src_image ), imagesy( $src_image ) ); + } else { + imagecopyresampled( $dst_image, $src_image, + 0,0,0,0, + $physicalWidth, $physicalHeight, imagesx( $src_image ), imagesy( $src_image ) ); + } - imagesavealpha($dst_image, true); + imagesavealpha( $dst_image, true ); call_user_func( $saveType, $dst_image, $dstPath ); imagedestroy( $dst_image ); -- 2.20.1