From beb2e7c0811dda3aa11de5c3710bee13d6402a42 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 28 Jul 2011 00:07:08 +0000 Subject: [PATCH] Move wfFixBoxImage() out of ImageFunctions and into MediaHandler. It's only used by ImageHandler and OggHandler. Where to move wfIsBadImage() so we can kill ImageFunctions? --- includes/ImageFunctions.php | 17 ----------------- includes/media/Generic.php | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/includes/ImageFunctions.php b/includes/ImageFunctions.php index d048a9dd49..aea00da711 100644 --- a/includes/ImageFunctions.php +++ b/includes/ImageFunctions.php @@ -75,20 +75,3 @@ function wfIsBadImage( $name, $contextTitle = false ) { wfProfileOut( __METHOD__ ); return $bad; } - -/** - * Calculate the largest thumbnail width for a given original file size - * such that the thumbnail's height is at most $maxHeight. - * @param $boxWidth Integer Width of the thumbnail box. - * @param $boxHeight Integer Height of the thumbnail box. - * @param $maxHeight Integer Maximum height expected for the thumbnail. - * @return Integer. - */ -function wfFitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) { - $idealWidth = $boxWidth * $maxHeight / $boxHeight; - $roundedUp = ceil( $idealWidth ); - if( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) - return floor( $idealWidth ); - else - return $roundedUp; -} diff --git a/includes/media/Generic.php b/includes/media/Generic.php index 48735ebf7d..0b3d546f26 100644 --- a/includes/media/Generic.php +++ b/includes/media/Generic.php @@ -441,6 +441,24 @@ abstract class MediaHandler { $file->getMimeType() ); } + /** + * Calculate the largest thumbnail width for a given original file size + * such that the thumbnail's height is at most $maxHeight. + * @param $boxWidth Integer Width of the thumbnail box. + * @param $boxHeight Integer Height of the thumbnail box. + * @param $maxHeight Integer Maximum height expected for the thumbnail. + * @return Integer. + */ + public static function fitBoxWidth( $boxWidth, $boxHeight, $maxHeight ) { + $idealWidth = $boxWidth * $maxHeight / $boxHeight; + $roundedUp = ceil( $idealWidth ); + if( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) { + return floor( $idealWidth ); + } else { + return $roundedUp; + } + } + function getDimensionsString( $file ) { return ''; } @@ -575,7 +593,7 @@ abstract class ImageHandler extends MediaHandler { # Height & width were both set if ( $params['width'] * $srcHeight > $params['height'] * $srcWidth ) { # Height is the relative smaller dimension, so scale width accordingly - $params['width'] = wfFitBoxWidth( $srcWidth, $srcHeight, $params['height'] ); + $params['width'] = self::fitBoxWidth( $srcWidth, $srcHeight, $params['height'] ); if ( $params['width'] == 0 ) { # Very small image, so we need to rely on client side scaling :( -- 2.20.1