From a00a681a5cc8dafc56e38da0472d823bb80fab65 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sat, 8 Jan 2011 11:49:09 +0000 Subject: [PATCH] Follow-up r79845: add function documentation; only call wfMakeDirsParent if we have a dest path. On r79845 I submitted a wrong commit summary, here is it for reference: (bug 6672) Images are now autorotated according to their EXIF orientation. Following the Flickr example, this only affects thumbnails, with the source unrotated. * Introduced BitmapHandler::canRotate() and BitmapHandler::getRotation() to check if rotation is supported and what the amount of rotation is * Factored out scaler determination into BitmapHandler::getScalerType() * ImageMagick uses the -auto-orientation option * GD uses imagerotate() * Unconditionally show the thumb size on the image page, don't know why this wasn't shown for SVGs etc. --- includes/media/Bitmap.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index c9ff9db97a..5d4de7eea2 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -176,7 +176,7 @@ class BitmapHandler extends ImageHandler { $scaler = 'client'; } - if ( $scaler != 'client' ) { + if ( $scaler != 'client' && $dstPath ) { if ( !wfMkdirParents( dirname( $dstPath ) ) ) { # Unable to create a path for the thumbnail return 'client'; @@ -647,6 +647,13 @@ class BitmapHandler extends ImageHandler { return $result; } + /** + * Try to read out the orientation of the file and return the angle that + * the file needs to be rotated to be viewed + * + * @param $file File + * @return int 0, 90, 180 or 270 + */ public function getRotation( $file ) { $data = $file->getMetadata(); if ( !$data ) { @@ -668,11 +675,23 @@ class BitmapHandler extends ImageHandler { } return 0; } + /** + * Returns whether the current scaler supports rotation (im and gd do) + * + * @return bool + */ public function canRotate() { $scaler = $this->getScalerType( null, false ); return $scaler == 'im' || $scaler == 'gd'; } + /** + * Rerurns whether the file needs to be rendered. Returns true if the + * file requires rotation and we are able to rotate it. + * + * @param $file File + * @return bool + */ public function mustRender( $file ) { return $this->canRotate() && $this->getRotation( $file ) != 0; } -- 2.20.1