31 return ( $file->getWidth() && $file->getHeight() );
40 return [
'img_width' =>
'width' ];
48 return in_array( $name, [
'width',
'height' ] ) && (int)$value > 0;
57 if ( isset( $params[
'physicalWidth'] ) ) {
58 $width = $params[
'physicalWidth'];
59 } elseif ( isset( $params[
'width'] ) ) {
60 $width = $params[
'width'];
65 # Removed for ProofreadPage
66 # $width = intval( $width );
76 if ( preg_match(
'/^(\d+)px$/', $str, $m ) ) {
77 return [
'width' => $m[1] ];
88 return [
'width' => $params[
'width'] ];
100 if ( !isset( $params[
'width'] ) ) {
104 if ( !isset( $params[
'page'] ) ) {
107 $params[
'page'] = (int)$params[
'page'];
108 if ( $params[
'page'] > $image->
pageCount() ) {
112 if ( $params[
'page'] < 1 ) {
117 $srcWidth = $image->
getWidth( $params[
'page'] );
118 $srcHeight = $image->
getHeight( $params[
'page'] );
120 if ( isset( $params[
'height'] ) && $params[
'height'] !== -1 ) {
121 # Height & width were both set
122 if ( $params[
'width'] * $srcHeight > $params[
'height'] * $srcWidth ) {
123 # Height is the relative smaller dimension, so scale width accordingly
124 $params[
'width'] =
self::fitBoxWidth( $srcWidth, $srcHeight, $params[
'height'] );
126 if ( $params[
'width'] == 0 ) {
127 # Very small image, so we need to rely on client side scaling :(
128 $params[
'width'] = 1;
131 $params[
'physicalWidth'] = $params[
'width'];
133 # Height was crap, unset it so that it will be calculated later
134 unset( $params[
'height'] );
138 if ( !isset( $params[
'physicalWidth'] ) ) {
139 # Passed all validations, so set the physicalWidth
140 $params[
'physicalWidth'] = $params[
'width'];
143 # Because thumbs are only referred to by width, the height always needs
144 # to be scaled by the width to keep the thumbnail sizes consistent,
145 # even if it was set inside the if block above
146 $params[
'physicalHeight'] = File::scaleHeight( $srcWidth, $srcHeight,
147 $params[
'physicalWidth'] );
149 # Set the height if it was not validated in the if block higher up
150 if ( !isset( $params[
'height'] ) || $params[
'height'] === -1 ) {
151 $params[
'height'] = $params[
'physicalHeight'];
154 if ( !$this->validateThumbParams( $params[
'physicalWidth'],
155 $params[
'physicalHeight'], $srcWidth, $srcHeight )
173 File $image,
int $requestWidth,
int $srcWidth,
int $srcHeight
178 if ( !$thumbnailSteps ) {
179 return $requestWidth;
182 $prevStep = $thumbnailSteps[0];
183 foreach ( $thumbnailSteps as $widthStep ) {
184 if ( ( $widthStep > $srcWidth ) && !$image->
isVectorized() ) {
204 if ( $widthStep == $requestWidth ) {
205 return $requestWidth;
207 if ( $widthStep > $requestWidth ) {
210 $prevStep = $widthStep;
226 private function validateThumbParams( &$width, &$height, $srcWidth, $srcHeight ) {
227 $width = (int)$width;
230 wfDebug( __METHOD__ .
": Invalid destination width: $width" );
234 if ( $srcWidth <= 0 ) {
235 wfDebug( __METHOD__ .
": Invalid source width: $srcWidth" );
240 $height = File::scaleHeight( $srcWidth, $srcHeight, $width );
241 if ( $height == 0 ) {
242 # Force height to be at least 1 pixel
258 if ( !$this->normaliseParams( $image, $params ) ) {
271 return @getimagesize(
$path );
277 $gis = @getimagesize(
$path );
283 if ( isset( $gis[
'bits'] ) ) {
284 $info[
'bits'] = $gis[
'bits'];
313 $lang = $this->getLanguage();
314 $nbytes = htmlspecialchars( $lang->formatSize( $file->getSize() ), ENT_QUOTES );
315 $widthheight =
wfMessage(
'widthheight' )
316 ->numParams( $file->getWidth(), $file->getHeight() )
317 ->inLanguage( $lang )
320 return "$widthheight ($nbytes)";
330 $pages = $file->pageCount();
331 if ( $pages ===
false || $pages <= 1 ) {
333 ->numParams( $file->getWidth(), $file->getHeight() )
334 ->sizeParams( $file->getSize() )
335 ->params(
'<span class="mime-type">' . $file->getMimeType() .
'</span>' )
336 ->inLanguage( $this->getLanguage() )
339 $msg =
wfMessage(
'file-info-size-pages' )
340 ->numParams( $file->getWidth(), $file->getHeight() )
341 ->sizeParams( $file->getSize() )
342 ->params(
'<span class="mime-type">' . $file->getMimeType() .
'</span>' )->numParams( $pages )
343 ->inLanguage( $this->getLanguage() )
357 $pages = $file->pageCount();
358 $lang = $this->getLanguage();
361 ->numParams( $file->getWidth(), $file->getHeight(), $pages )
362 ->inLanguage( $lang )->text();
365 ->numParams( $file->getWidth(), $file->getHeight() )->inLanguage( $lang )->text();
373 $params = parent::sanitizeParamsForBucketing( $params );
377 unset( $params[
'height'] );
378 unset( $params[
'physicalHeight'] );
385class_alias( ImageHandler::class,
'ImageHandler' );
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.
A class containing constants representing the names of configuration variables.
const ThumbnailSteps
Name constant for the ThumbnailSteps setting, for use with Config::get()