From ddd5f9752c2314e2345cafe2630d62b7766798cd Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Tue, 13 Jan 2004 21:03:47 +0000 Subject: [PATCH] Offer GD-based image resizing as well as ImageMagick based one --- LocalSettings.sample | 13 +++++++--- includes/Skin.php | 62 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/LocalSettings.sample b/LocalSettings.sample index 758631a911..01a8657437 100644 --- a/LocalSettings.sample +++ b/LocalSettings.sample @@ -38,13 +38,18 @@ $wgDBsqlpassword = "sqlpass"; $wgDBminWordLen = 3; # Match this to your MySQL fulltext $wgDBtransactions = false; # Set to true if using InnoDB tables -# This is the location of the convert program -# from the ImageMagick toolbox. You need it for -# the image resizing functionality. # -# Set $wgUseImageResize to true if you want to use this feature +# Set $wgUseImageResize to true if you want to enable dynamic +# server side image resizing ("Thumbnails") # $wgUseImageResize = false; +# Resizing can be done using PHP's internal image libraries +# or using ImageMagick. The later supports more file formats +# than PHP, which only supports PNG, GIF, JPG, XBM and WBMP. +# +# Set $wgUseImageMagick to true to use Image Magick instead +# of the builtin functions +$wgUseImageMagick = false; $wgImageMagickConvertCommand = "/usr/bin/convert"; # Turn this on during database maintenance diff --git a/includes/Skin.php b/includes/Skin.php index 4b1a81fc39..12111820e4 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1509,6 +1509,7 @@ class Skin { function createThumb( $name, $width ) { global $wgUploadDirectory; global $wgImageMagickConvertCommand; + global $wgUseImageMagick; $imgPath = wfImagePath( $name ); $thumbName = $width."px-".$icon.$name; $thumbPath = wfImageArchiveDir( $thumbName, "thumb" )."/".$thumbName; @@ -1516,11 +1517,68 @@ class Skin { if ( (! file_exists( $thumbPath )) || ( filemtime($thumbPath) < filemtime($imgPath) ) ) { - $cmd = $wgImageMagickConvertCommand . + if ( $wgUseImageMagick ) { + # use ImageMagick + $cmd = $wgImageMagickConvertCommand . " -quality 95 -geometry {$width}x ". escapeshellarg($imgPath) . " " . escapeshellarg($thumbPath); - $conv = shell_exec( $cmd ); + $conv = shell_exec( $cmd ); + } else { + # Use PHP's builtin GD library functions. + # + # First find out what kind of file this is, and select the correct + # input routine for this. + list($src_width, $src_height, $src_type, $src_attr) = getimagesize( $imgPath ); + switch( $src_type ) { + case 1: # GIF + $src_image = imagecreatefromgif( $imgPath ); + break; + case 2: # JPG + $src_image = imagecreatefromjpeg( $imgPath ); + break; + case 3: # PNG + $src_image = imagecreatefrompng( $imgPath ); + break; + case 15: # WBMP for WML + $src_image = imagecreatefromwbmp( $imgPath ); + break; + case 16: # XBM + $src_image = imagecreatefromxbm( $imgPath ); + break; + default: + return "Image type not supported"; + break; + } + $height = floor( $src_height * ( $width/$src_width ) ); + $dst_image = imagecreatetruecolor( $width, $height ); + imagecopyresampled( $dst_image, $src_image, + 0,0,0,0, + $width, $height, $src_width, $src_height ); + switch( $src_type ) { + case 1: # GIF + case 3: # PNG + case 15: # WBMP + case 16: # XBM + #$thumbUrl .= ".png"; + #$thumbPath .= ".png"; + imagepng( $dst_image, $thumbPath ); + break; + case 2: # JPEG + #$thumbUrl .= ".jpg"; + #$thumbPath .= ".jpg"; + imageinterlace( $dst_image ); + imagejpeg( $dst_image, $thumbPath, 95 ); + break; + default: + break; + } + imagedestroy( $dst_image ); + imagedestroy( $src_image ); + + + } + } return $thumbUrl; } -- 2.20.1