Index: trunk/phase3/includes/media/ExifBitmap.php |
— | — | @@ -134,12 +134,17 @@ |
135 | 135 | * @return array |
136 | 136 | */ |
137 | 137 | function getImageSize( $image, $path ) { |
| 138 | + global $wgEnableAutoRotation; |
138 | 139 | $gis = parent::getImageSize( $image, $path ); |
139 | 140 | |
140 | 141 | // Don't just call $image->getMetadata(); File::getPropsFromPath() calls us with a bogus object. |
141 | 142 | // This may mean we read EXIF data twice on initial upload. |
142 | | - $meta = $this->getMetadata( $image, $path ); |
143 | | - $rotation = $this->getRotationForExif( $meta ); |
| 143 | + if ( $wgEnableAutoRotation ) { |
| 144 | + $meta = $this->getMetadata( $image, $path ); |
| 145 | + $rotation = $this->getRotationForExif( $meta ); |
| 146 | + } else { |
| 147 | + $rotation = 0; |
| 148 | + } |
144 | 149 | |
145 | 150 | if ($rotation == 90 || $rotation == 270) { |
146 | 151 | $width = $gis[0]; |
Index: trunk/phase3/tests/phpunit/includes/media/ExifRotationTest.php |
— | — | @@ -20,10 +20,15 @@ |
21 | 21 | global $wgShowEXIF; |
22 | 22 | $this->show = $wgShowEXIF; |
23 | 23 | $wgShowEXIF = true; |
| 24 | + |
| 25 | + global $wgEnableAutoRotation; |
| 26 | + $this->oldAuto = $wgEnableAutoRotation; |
| 27 | + $wgEnableAutoRotation = true; |
24 | 28 | } |
25 | 29 | public function tearDown() { |
26 | | - global $wgShowEXIF; |
| 30 | + global $wgShowEXIF, $wgEnableAutoRotation; |
27 | 31 | $wgShowEXIF = $this->show; |
| 32 | + $wgEnableAutoRotation = $this->oldAuto; |
28 | 33 | } |
29 | 34 | |
30 | 35 | /** |
— | — | @@ -31,6 +36,9 @@ |
32 | 37 | * @dataProvider providerFiles |
33 | 38 | */ |
34 | 39 | function testMetadata( $name, $type, $info ) { |
| 40 | + if ( !BitmapHandler::canRotate() ) { |
| 41 | + $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." ); |
| 42 | + } |
35 | 43 | $file = UnregisteredLocalFile::newFromPath( $this->filePath . $name, $type ); |
36 | 44 | $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" ); |
37 | 45 | $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" ); |
— | — | @@ -41,6 +49,9 @@ |
42 | 50 | * @dataProvider providerFiles |
43 | 51 | */ |
44 | 52 | function testRotationRendering( $name, $type, $info, $thumbs ) { |
| 53 | + if ( !BitmapHandler::canRotate() ) { |
| 54 | + $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." ); |
| 55 | + } |
45 | 56 | foreach( $thumbs as $size => $out ) { |
46 | 57 | if( preg_match('/^(\d+)px$/', $size, $matches ) ) { |
47 | 58 | $params = array( |
— | — | @@ -109,6 +120,95 @@ |
110 | 121 | ) |
111 | 122 | ); |
112 | 123 | } |
| 124 | + |
| 125 | + /** |
| 126 | + * Same as before, but with auto-rotation disabled. |
| 127 | + * @dataProvider providerFilesNoAutoRotate |
| 128 | + */ |
| 129 | + function testMetadataNoAutoRotate( $name, $type, $info ) { |
| 130 | + global $wgEnableAutoRotation; |
| 131 | + $wgEnableAutoRotation = false; |
| 132 | + |
| 133 | + $file = UnregisteredLocalFile::newFromPath( $this->filePath . $name, $type ); |
| 134 | + $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" ); |
| 135 | + $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" ); |
| 136 | + |
| 137 | + $wgEnableAutoRotation = true; |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * |
| 142 | + * @dataProvider providerFilesNoAutoRotate |
| 143 | + */ |
| 144 | + function testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs ) { |
| 145 | + global $wgEnableAutoRotation; |
| 146 | + $wgEnableAutoRotation = false; |
| 147 | + |
| 148 | + foreach( $thumbs as $size => $out ) { |
| 149 | + if( preg_match('/^(\d+)px$/', $size, $matches ) ) { |
| 150 | + $params = array( |
| 151 | + 'width' => $matches[1], |
| 152 | + ); |
| 153 | + } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) { |
| 154 | + $params = array( |
| 155 | + 'width' => $matches[1], |
| 156 | + 'height' => $matches[2] |
| 157 | + ); |
| 158 | + } else { |
| 159 | + throw new MWException('bogus test data format ' . $size); |
| 160 | + } |
| 161 | + |
| 162 | + $file = $this->localFile( $name, $type ); |
| 163 | + $thumb = $file->transform( $params, File::RENDER_NOW ); |
| 164 | + |
| 165 | + $this->assertEquals( $out[0], $thumb->getWidth(), "$name: thumb reported width check for $size" ); |
| 166 | + $this->assertEquals( $out[1], $thumb->getHeight(), "$name: thumb reported height check for $size" ); |
| 167 | + |
| 168 | + $gis = getimagesize( $thumb->getPath() ); |
| 169 | + if ($out[0] > $info['width']) { |
| 170 | + // Physical image won't be scaled bigger than the original. |
| 171 | + $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size"); |
| 172 | + $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size"); |
| 173 | + } else { |
| 174 | + $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size"); |
| 175 | + $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size"); |
| 176 | + } |
| 177 | + } |
| 178 | + $wgEnableAutoRotation = true; |
| 179 | + } |
| 180 | + |
| 181 | + function providerFilesNoAutoRotate() { |
| 182 | + return array( |
| 183 | + array( |
| 184 | + 'landscape-plain.jpg', |
| 185 | + 'image/jpeg', |
| 186 | + array( |
| 187 | + 'width' => 1024, |
| 188 | + 'height' => 768, |
| 189 | + ), |
| 190 | + array( |
| 191 | + '800x600px' => array( 800, 600 ), |
| 192 | + '9999x800px' => array( 1067, 800 ), |
| 193 | + '800px' => array( 800, 600 ), |
| 194 | + '600px' => array( 600, 450 ), |
| 195 | + ) |
| 196 | + ), |
| 197 | + array( |
| 198 | + 'portrait-rotated.jpg', |
| 199 | + 'image/jpeg', |
| 200 | + array( |
| 201 | + 'width' => 1024, // since not rotated |
| 202 | + 'height' => 768, // since not rotated |
| 203 | + ), |
| 204 | + array( |
| 205 | + '800x600px' => array( 800, 600 ), |
| 206 | + '9999x800px' => array( 1067, 800 ), |
| 207 | + '800px' => array( 800, 600 ), |
| 208 | + '600px' => array( 600, 450 ), |
| 209 | + ) |
| 210 | + ) |
| 211 | + ); |
| 212 | + } |
113 | 213 | |
114 | 214 | |
115 | 215 | const TEST_WIDTH = 100; |