24use Wikimedia\AtEase\AtEase;
41 return ( $file->getWidth() && $file->getHeight() );
50 return [
'img_width' =>
'width' ];
58 return in_array( $name, [
'width',
'height' ] ) && $value > 0;
67 if ( isset(
$params[
'physicalWidth'] ) ) {
68 $width =
$params[
'physicalWidth'];
69 } elseif ( isset(
$params[
'width'] ) ) {
75 # Removed for ProofreadPage
76 # $width = intval( $width );
86 if ( preg_match(
'/^(\d+)px$/', $str, $m ) ) {
87 return [
'width' => $m[1] ];
98 return [
'width' =>
$params[
'width'] ];
110 if ( !isset(
$params[
'width'] ) ) {
114 if ( !isset(
$params[
'page'] ) ) {
118 if (
$params[
'page'] > $image->pageCount() ) {
119 $params[
'page'] = $image->pageCount();
127 $srcWidth = $image->getWidth(
$params[
'page'] );
128 $srcHeight = $image->getHeight(
$params[
'page'] );
131 # Height & width were both set
132 if (
$params[
'width'] * $srcHeight >
$params[
'height'] * $srcWidth ) {
133 # Height is the relative smaller dimension, so scale width accordingly
137 # Very small image, so we need to rely on client side scaling :(
143 # Height was crap, unset it so that it will be calculated later
148 if ( !isset(
$params[
'physicalWidth'] ) ) {
149 # Passed all validations, so set the physicalWidth
154 # Because thumbs are only referred to by width, the height always needs
155 # to be scaled by the width to keep the thumbnail sizes consistent,
156 # even if it was set inside the if block above
157 $params[
'physicalHeight'] = File::scaleHeight( $srcWidth, $srcHeight,
160 # Set the height if it was not validated in the if block higher up
165 if ( !$this->validateThumbParams(
$params[
'physicalWidth'],
166 $params[
'physicalHeight'], $srcWidth, $srcHeight )
183 private function validateThumbParams( &$width, &$height, $srcWidth, $srcHeight ) {
184 $width = (int)$width;
187 wfDebug( __METHOD__ .
": Invalid destination width: $width" );
191 if ( $srcWidth <= 0 ) {
192 wfDebug( __METHOD__ .
": Invalid source width: $srcWidth" );
198 if ( $height == 0 ) {
199 # Force height to be at least 1 pixel
220 if ( $image->mustRender() ||
$params[
'width'] < $image->getWidth() ) {
226 AtEase::suppressWarnings();
227 $gis = getimagesize(
$path );
228 AtEase::restoreWarnings();
235 $gis = @getimagesize(
$path );
241 if ( isset( $gis[
'bits'] ) ) {
242 $info[
'bits'] = $gis[
'bits'];
261 return $image->getWidth() * $image->getHeight();
272 $nbytes = htmlspecialchars(
$wgLang->formatSize( $file->getSize() ) );
273 $widthheight =
wfMessage(
'widthheight' )
274 ->numParams( $file->getWidth(), $file->getHeight() )->escaped();
276 return "$widthheight ($nbytes)";
286 $pages = $file->pageCount();
287 if ( $pages ===
false || $pages <= 1 ) {
288 $msg =
wfMessage(
'file-info-size' )->numParams( $file->getWidth(),
289 $file->getHeight() )->sizeParams( $file->getSize() )->params(
290 '<span class="mime-type">' . $file->getMimeType() .
'</span>' )->parse();
292 $msg =
wfMessage(
'file-info-size-pages' )->numParams( $file->getWidth(),
293 $file->getHeight() )->sizeParams( $file->getSize() )->params(
294 '<span class="mime-type">' . $file->getMimeType() .
'</span>' )->numParams( $pages )->parse();
307 $pages = $file->pageCount();
310 ->numParams( $file->getWidth(), $file->getHeight(), $pages )->text();
313 ->numParams( $file->getWidth(), $file->getHeight() )->text();
326 unset(
$params[
'physicalHeight'] );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
array $params
The job parameters.
static scaleHeight( $srcWidth, $srcHeight, $dstWidth)
Calculate the height of a thumbnail using the source and destination width.
Media handler abstract base class for images.
canRender( $file)
True if the handled types can be transformed.to overridebool
getImageSize( $image, $path)
Get an image size array like that returned by getimagesize(), or false if it can't be determined.
sanitizeParamsForBucketing( $params)
Returns a normalised params array for which parameters have been cleaned up for bucketing purposes....
getImageArea( $image)
Function that returns the number of pixels to be thumbnailed.
getParamMap()
Get an associative array mapping magic word IDs to parameter names.Will be used by the parser to iden...
getSizeAndMetadata( $state, $path)
Get image size information and metadata array.
normaliseParams( $image, &$params)
Changes the parameter array as necessary, ready for transformation.Should be idempotent....
parseParamString( $str)
Parse a param string made with makeParamString back into an array.array|false Array of parameters or ...
makeParamString( $params)
Merge a parameter array into a string appropriate for inclusion in filenames.string
getLongDesc( $file)
Long description.Shown under image on image description page surrounded by ().to overridestring
validateParam( $name, $value)
Validate a thumbnail parameter at parse time.Return true to accept the parameter, and false to reject...
getScriptedTransform( $image, $script, $params)
Get a MediaTransformOutput object representing an alternate of the transformed output which will call...
getScriptParams( $params)
getDimensionsString( $file)
Shown in file history box on image description page.to overridestring Dimensions
getShortDesc( $file)
Short description.Shown on Special:Search results.to overridestring
Media transform output for images.