MediaWiki  REL1_24
MockImageHandler.php
Go to the documentation of this file.
00001 <?php
00031 class MockImageHandler {
00032 
00046     static function doFakeTransform( $that, $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
00047         # Example of what we receive:
00048         # $image: LocalFile
00049         # $dstPath: /tmp/transform_7d0a7a2f1a09-1.jpg
00050         # $dstUrl : http://example.com/images/thumb/0/09/Bad.jpg/320px-Bad.jpg
00051         # $params:  width: 320,  descriptionUrl http://trunk.dev/wiki/File:Bad.jpg
00052 
00053         $that->normaliseParams( $image, $params );
00054 
00055         $scalerParams = array(
00056             # The size to which the image will be resized
00057             'physicalWidth' => $params['physicalWidth'],
00058             'physicalHeight' => $params['physicalHeight'],
00059             'physicalDimensions' => "{$params['physicalWidth']}x{$params['physicalHeight']}",
00060             # The size of the image on the page
00061             'clientWidth' => $params['width'],
00062             'clientHeight' => $params['height'],
00063             # Comment as will be added to the EXIF of the thumbnail
00064             'comment' => isset( $params['descriptionUrl'] ) ?
00065                     "File source: {$params['descriptionUrl']}" : '',
00066             # Properties of the original image
00067             'srcWidth' => $image->getWidth(),
00068             'srcHeight' => $image->getHeight(),
00069             'mimeType' => $image->getMimeType(),
00070             'dstPath' => $dstPath,
00071             'dstUrl' => $dstUrl,
00072         );
00073 
00074         # In some cases, we do not bother generating a thumbnail.
00075         if ( !$image->mustRender() &&
00076             $scalerParams['physicalWidth'] == $scalerParams['srcWidth']
00077             && $scalerParams['physicalHeight'] == $scalerParams['srcHeight']
00078         ) {
00079             wfDebug( __METHOD__ . ": returning unscaled image\n" );
00080             // getClientScalingThumbnailImage is protected
00081             return $that->doClientImage( $image, $scalerParams );
00082         }
00083 
00084         return new ThumbnailImage( $image, $dstUrl, false, $params );
00085     }
00086 }