r102507 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102506‎ | r102507 | r102508 >
Date:11:37, 9 November 2011
Author:hashar
Status:ok
Tags:
Comment:
fix thumb rotation in non bilinear mode

physical height and width are already switched upstream if there is an
exif rotation indicator. So we did a double rotation and used bad
shrinking parameters. Found this issue with our test suite \o/

TEST PLAN:

$ ./phpunit.php --testdox includes/media/ExifRotationTest.php
PHPUnit 3.6.2 by Sebastian Bergmann.

ExifRotation
[x] Metadata
[x] Rotation rendering
[x] Bitmap extract pre rotation dimensions
$

$ make noparser
<did not get any errors related to vips or images>
$

I have also tested rendering using [[Special:VipsTest]] against the
tests/phpunit/data/media/Portrait-rotated.jpg I have uploaded locally.
Modified paths:
  • /trunk/extensions/VipsScaler/VipsScaler_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/VipsScaler/VipsScaler_body.php
@@ -131,18 +131,22 @@
132132 # Do the resizing
133133 $rotation = 360 - $handler->getRotation( $file );
134134
 135+ wfDebug( __METHOD__ . " rotating '{$file->getName()}' by {$rotation}°\n" );
135136 if ( empty( $options['bilinear'] ) ) {
136137 # Calculate shrink factors. Offsetting by 0.5 pixels is required
137138 # because of rounding down of the target size by VIPS. See 25990#c7
138 - if ( $rotation % 180 == 90 ) {
139 - # Rotated 90 degrees, so width = height and vice versa
140 - $rx = $params['srcWidth'] / ($params['physicalHeight'] + 0.5);
141 - $ry = $params['srcHeight'] / ($params['physicalWidth'] + 0.5);
142 - } else {
143 - $rx = $params['srcWidth'] / ($params['physicalWidth'] + 0.5);
144 - $ry = $params['srcHeight'] / ($params['physicalHeight'] + 0.5);
145 - }
 139+ # No need to invert source and physical dimensions. They already got switched if needed.
 140+ $rx = $params['srcWidth'] / ($params['physicalWidth'] + 0.5);
 141+ $ry = $params['srcHeight'] / ($params['physicalHeight'] + 0.5);
146142
 143+ wfDebug( sprintf(
 144+ "%s to shrink '%s'. Source: %sx%s, Physical: %sx%s. Shrink factors (rx,ry) = %sx%s.\n",
 145+ __METHOD__, $file->getName(),
 146+ $params['srcWidth'], $params['srcHeight'],
 147+ $params['physicalWidth'], $params['physicalHeight'],
 148+ $rx, $ry
 149+ ));
 150+
147151 $commands[] = new VipsCommand( $wgVipsCommand, array( 'im_shrink', $rx, $ry ) );
148152 } else {
149153 if ( $rotation % 180 == 90 ) {
@@ -152,6 +156,14 @@
153157 $dstWidth = $params['physicalWidth'];
154158 $dstHeight = $params['physicalHeight'];
155159 }
 160+ wfDebug( sprintf(
 161+ "%s to bilinear resize %s. Source: %sx%s, Physical: %sx%s. Destination: %sx%s\n",
 162+ __METHOD__, $file->getName(),
 163+ $params['srcWidth'], $params['srcHeight'],
 164+ $params['physicalWidth'], $params['physicalHeight'],
 165+ $dstWidth, $dstHeight
 166+ ));
 167+
156168 $commands[] = new VipsCommand( $wgVipsCommand,
157169 array( 'im_resize_linear', $dstWidth, $dstHeight ) );
158170 }

Status & tagging log