From 6606ab513e84fa943655a2b7be0140b3f8359b9f Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Sun, 9 May 2004 10:52:50 +0000 Subject: [PATCH] Image bounding box can be specified instead of width, e.g. as 100x100px, making the image not wider than 100px and not higher than 100px, keeping aspect ratio. --- RELEASE-NOTES | 7 +++++++ includes/Image.php | 1 + includes/Skin.php | 35 +++++++++++++++++++++++++---------- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 1ec7b6de85..8b4a2505bf 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -9,6 +9,9 @@ Look & layout: Wiki features: * Image captions can now include links and other basic formatting +* Image bounding box can be specified instead of width, e.g. as + 100x100px, making the image not wider than 100px and not higher + than 100px, keeping aspect ratio. * Templates have been expanded with parameters, and separated from the MediaWiki: localization scheme. * Categories more or less work @@ -23,6 +26,8 @@ Metadata and output: Optional modules: * WikiHiero hieroglyphic module can be added (separate download) +* Timeline module can be added (separate download). + Requires ploticus. * TeX now has an experimental MathML output mode (incomplete) Installation and upgrading: @@ -39,6 +44,8 @@ Code and compatibility: * Should now run clean with error reporting set to E_ALL. * register_globals hack from 1.2 has been replaced with safer code * Bundled PHPTAL 0.7.0 from http://phptal.sourceforge.net/ + (with some patches) +* Most image-related code moved to Image.php === Caveats === diff --git a/includes/Image.php b/includes/Image.php index f50e69baa9..de089e342a 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -138,6 +138,7 @@ class Image # BZZZT return ""; } + if( $width > $this->width ) { # Don't make an image bigger than the source return $this->getURL(); diff --git a/includes/Skin.php b/includes/Skin.php index 13692961a7..7b53b6ee3e 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1721,7 +1721,7 @@ class Skin { $mwFramed =& MagicWord::get( MAG_IMG_FRAMED ); $alt = $part[count($part)-1]; - $framed=$thumb=false; + $height = $framed = $thumb = false; foreach( $part as $key => $val ) { if ( ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) { @@ -1740,7 +1740,12 @@ class Skin { $align = "none"; } elseif ( ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) { # $match is the image width in pixels - $width = intval($match); + if ( preg_match( "/^([0-9]*)x([0-9]*)$/", $match, $m ) ) { + $width = intval( $m[1] ); + $height = intval( $m[2] ); + } else { + $width = intval($match); + } } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) { $framed=true; } @@ -1767,12 +1772,19 @@ class Skin { if ( ! isset($width) ) { $width = 180; } - return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $framed ).$postfix; + return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed ).$postfix; } elseif ( isset($width) ) { # Create a resized image, without the additional thumbnail # features + + if ( ( ! $height === false ) + && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) { + print "height=$height
\nimg->getHeight() = ".$img->getHeight()."
\n"; + print "rescaling by factor ". $height / $img->getHeight() . "
\n"; + $width = $img->getWidth() * $height / $img->getHeight(); + } $url = $img->createThumb( $width ); } } # endif $wgUseImageResize @@ -1798,7 +1810,7 @@ class Skin { } - function makeThumbLinkObj( $img, $label = "", $align = "right", $boxwidth = 180, $framed=false ) { + function makeThumbLinkObj( $img, $label = "", $align = "right", $boxwidth = 180, $boxheight=false, $framed=false ) { global $wgStylePath, $wgLang; # $image = Title::makeTitle( Namespace::getImage(), $name ); $url = $img->getURL(); @@ -1818,17 +1830,20 @@ class Skin { { // Use image dimensions, don't scale $boxwidth = $width; + $oboxwidth = $boxwidth + 2; $boxheight = $height; $thumbUrl = $url; } else { - $boxheight = intval( $height/($width/$boxwidth) ); - # if ( $boxwidth > $width ) { - # $boxwidth = $width; - # $boxheight = $height; - #} + $h = intval( $height/($width/$boxwidth) ); + $oboxwidth = $boxwidth + 2; + if ( ( ! $boxheight === false ) && ( $h > $boxheight ) ) + { + $boxwidth *= $boxheight/$h; + } else { + $boxheight = $h; + } $thumbUrl = $img->createThumb( $boxwidth ); } - $oboxwidth = $boxwidth + 2; $u = $img->getEscapeLocalURL(); -- 2.20.1