Merge "Generate thumbnails based on buckets"
[lhc/web/wiklou.git] / includes / media / Bitmap.php
index 8ac58ff..9a3e927 100644 (file)
@@ -360,7 +360,30 @@ class BitmapHandler extends ImageHandler {
                                }
                        }
                } elseif ( $params['mimeType'] == 'image/x-xcf' ) {
-                       $animation_post = array( '-layers', 'merge' );
+                       // Before merging layers, we need to set the background
+                       // to be transparent to preserve alpha, as -layers merge
+                       // merges all layers on to a canvas filled with the
+                       // background colour. After merging we reset the background
+                       // to be white for the default background colour setting
+                       // in the PNG image (which is used in old IE)
+                       $animation_post = array(
+                               '-background', 'transparent',
+                               '-layers', 'merge',
+                               '-background', 'white',
+                       );
+                       wfSuppressWarnings();
+                       $xcfMeta = unserialize( $image->getMetadata() );
+                       wfRestoreWarnings();
+                       if ( $xcfMeta
+                               && isset( $xcfMeta['colorType'] )
+                               && $xcfMeta['colorType'] === 'greyscale-alpha'
+                               && version_compare( $this->getMagickVersion(), "6.8.9-3" ) < 0
+                       ) {
+                               // bug 66323 - Greyscale images not rendered properly.
+                               // So only take the "red" channel.
+                               $channelOnly = array( '-channel', 'R', '-separate' );
+                               $animation_post = array_merge( $animation_post, $channelOnly );
+                       }
                }
 
                // Use one thread only, to avoid deadlock bugs on OOM