* Resizing transparent GIF images with GD now retains transparency by skipping
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 23 Aug 2007 18:28:21 +0000 (18:28 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 23 Aug 2007 18:28:21 +0000 (18:28 +0000)
  resampling

RELEASE-NOTES
includes/media/Bitmap.php

index 12ba6a7..978eb26 100644 (file)
@@ -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 ==
 
index c43e571..245abb8 100644 (file)
@@ -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 );