Page MenuHomePhabricator

Image.php.diff

Authored By
bzimport
Nov 21 2014, 8:47 PM
Size
4 KB
Referenced Files
None
Subscribers
None

Image.php.diff

Index: includes/Image.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/Image.php,v
retrieving revision 1.110
diff -u -r1.110 Image.php
--- includes/Image.php 2 Aug 2005 10:40:42 -0000 1.110
+++ includes/Image.php 12 Aug 2005 09:05:59 -0000
@@ -819,6 +819,16 @@
return NULL; //can't make bitmap
}
}
+ $this->load();
+ $typemap = $this->getThumbRenderStrategyArray();
+ if( !isset( $typemap[$this->mime] ) ) {
+ return $thumb;
+ }
+ list( $loader, $colorStyle, $saveType ) = $typemap[$this->mime];
+
+ if( ($saveType == 'imagepng') && ($this->extension != 'png') ) {
+ $thumb = substr( $thumb, 0, 0 - strlen( $this->extension )) . 'png'; # If a non-PNG image uses thumbnails in PNG format, rectify the extension.
+ }
return $thumb;
}
@@ -980,6 +990,43 @@
} // END OF function renderThumb
/**
+ * Just tells how certain types of images get transformed when turned into thumbnails.
+ * The values are arrays which contain:
+ * name of image load function ("input routine")
+ * what color depth the target image should have ("color type")
+ * the image write function ("save type")
+ *
+ * Sure a big name for a simple function ;-)
+ *
+ * @access private
+ */
+
+ function getThumbRenderStrategyArray() {
+ return array(
+ # 'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif' ), # Smaller file size
+ 'image/gif' => array( 'imagecreatefromgif', 'truecolor', 'imagepng' ), # Better quality
+ 'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', array( &$this, 'imageJpegWrapper' ) ),
+ # 'image/png' => array( 'imagecreatefrompng', 'bits', 'imagepng' ), # Smaller file size
+ 'image/png' => array( 'imagecreatefrompng', 'truecolor', 'imagepng' ), # Better quality
+ # 'image/vnd.wap.wmbp' => array( 'imagecreatefromwbmp', 'palette', 'imagewbmp' ), # Not compatible with every browser (or so I'm told)
+ 'image/vnd.wap.wmbp' => array( 'imagecreatefromwbmp', 'palette', 'imagepng' ), # More browser compatible. WBMP is monochrome, so let's try to get away with a 256 color thumbnail
+ # 'image/xbm' => array( 'imagecreatefromxbm', 'palette', 'imagexbm' ), # Not compatible with every browser (well, NS & MSIE work, dunno about others)
+ 'image/xbm' => array( 'imagecreatefromxbm', 'palette', 'imagepng' ), # More browser compatible. XPM is monochrome (black & white), so let's try to get away with a 256 color thumbnail
+ );
+ /**
+ * Meaning of the "color types":
+ * palette - the thumbnail image should be a 256 color image
+ * truecolor - the thumbnail image should be a truecolor image
+ * bits - the thumbnail image should be a truecolor image only if the source image
+ * has more than 256 colors (otherwise, it will be a 256 color image)
+ *
+ * Please be aware that downsampled versions of 256 color images typically contain much
+ * more than 256 colors (because of interpolation)! So here would be a place to trade
+ * thumbnail quality against thumbnail file size. Plus the vague compatability issue...
+ */
+ }
+
+ /**
* Really render a thumbnail
* Call this only for images for which canRender() returns true.
*
@@ -1024,13 +1071,7 @@
# First find out what kind of file this is, and select the correct
# input routine for this.
- $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' ),
- );
+ $typemap = $this->getThumbRenderStrategyArray();
if( !isset( $typemap[$this->mime] ) ) {
$err = 'Image type not supported';
wfDebug( "$err\n" );
@@ -1043,6 +1084,11 @@
wfDebug( "$err\n" );
return $err;
}
+ if( !function_exists( $saveType ) ) {
+ $err = "Incomplete GD library configuration: missing function $saveType";
+ wfDebug( "$err\n" );
+ return $err;
+ }
if( $colorStyle == 'palette' ) {
$truecolor = false;
} elseif( $colorStyle == 'truecolor' ) {

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1831
Default Alt Text
Image.php.diff (4 KB)

Event Timeline