From: Brion Vibber Date: Mon, 11 Jul 2005 01:52:27 +0000 (+0000) Subject: * (bug 2780) Fix thumbnail generation with GD for new image schema X-Git-Tag: 1.5.0beta4~163 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=aa47997796e8a2a44ea4b472fa794f1a435d223f;p=lhc%2Fweb%2Fwiklou.git * (bug 2780) Fix thumbnail generation with GD for new image schema --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index ced38e9c08..cb16a05db0 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -558,8 +558,7 @@ of MediaWiki:Newpagetext) to &action=edit, if page is new. * (bug 2761) fix capitalization of "i" in Turkish * (bug 2789) memcached image metadata now cleared after deletion * Add serialized version number to image metadata cache records -* (bug 2769) Use '-' form for language consistently on command-line -* Fixlets to rebuildImages.php: clear memcached, indicate missing +* (bug 2780) Fix thumbnail generation with GD for new image schema === Caveats === diff --git a/includes/Image.php b/includes/Image.php index 02424dc83e..2812f47336 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -1028,30 +1028,34 @@ class Image # First find out what kind of file this is, and select the correct # input routine for this. - $truecolor = false; + $typemap = array( + 'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif' ), + 'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', array( &$this, 'imageJpegWrapper' ) ), + 'image/png' => array( 'imagecreatefrompng', 'bits', 'imagepng' ), + 'image/vnd.wap.wmbp' => array( 'imagecreatefromwbmp', 'palette', 'imagewbmp' ), + 'image/xbm' => array( 'imagecreatefromxbm', 'palette', 'imagexbm' ), + ); + if( !isset( $typemap[$this->mime] ) ) { + $err = 'Image type not supported'; + wfDebug( "$err\n" ); + return $err; + } + list( $loader, $colorStyle, $saveType ) = $typemap[$this->mime]; - switch( $this->type ) { - case 1: # GIF - $src_image = imagecreatefromgif( $this->imagePath ); - break; - case 2: # JPG - $src_image = imagecreatefromjpeg( $this->imagePath ); - $truecolor = true; - break; - case 3: # PNG - $src_image = imagecreatefrompng( $this->imagePath ); - $truecolor = ( $this->bits > 8 ); - break; - case 15: # WBMP for WML - $src_image = imagecreatefromwbmp( $this->imagePath ); - break; - case 16: # XBM - $src_image = imagecreatefromxbm( $this->imagePath ); - break; - default: - return 'Image type not supported'; - break; + if( !function_exists( $loader ) ) { + $err = "Incomplete GD library configuration: missing function $loader"; + wfDebug( "$err\n" ); + return $err; } + if( $colorStyle == 'palette' ) { + $truecolor = false; + } elseif( $colorStyle == 'truecolor' ) { + $truecolor = true; + } elseif( $colorStyle == 'bits' ) { + $truecolor = ( $this->bits > 8 ); + } + + $src_image = call_user_func( $loader, $this->imagePath ); if ( $truecolor ) { $dst_image = imagecreatetruecolor( $width, $height ); } else { @@ -1060,20 +1064,7 @@ class Image imagecopyresampled( $dst_image, $src_image, 0,0,0,0, $width, $height, $this->width, $this->height ); - switch( $this->type ) { - case 1: # GIF - case 3: # PNG - case 15: # WBMP - case 16: # XBM - imagepng( $dst_image, $thumbPath ); - break; - case 2: # JPEG - imageinterlace( $dst_image ); - imagejpeg( $dst_image, $thumbPath, 95 ); - break; - default: - break; - } + call_user_func( $saveType, $dst_image, $thumbPath ); imagedestroy( $dst_image ); imagedestroy( $src_image ); } @@ -1090,6 +1081,11 @@ class Image } } + function imageJpegWrapper( $dst_image, $thumbPath ) { + imageinterlace( $dst_image ); + imagejpeg( $dst_image, $thumbPath, 95 ); + } + /** * Get all thumbnail names previously generated for this image */