Index: trunk/phase3/tests/phpunit/includes/api/RandomImageGenerator.php |
— | — | @@ -27,11 +27,11 @@ |
28 | 28 | class RandomImageGenerator { |
29 | 29 | |
30 | 30 | private $dictionaryFile; |
31 | | - private $minWidth = 400; |
32 | | - private $maxWidth = 800; |
33 | | - private $minHeight = 400; |
34 | | - private $maxHeight = 800; |
35 | | - private $shapesToDraw = 5; |
| 31 | + private $minWidth = 400 ; |
| 32 | + private $maxWidth = 800 ; |
| 33 | + private $minHeight = 400 ; |
| 34 | + private $maxHeight = 800 ; |
| 35 | + private $shapesToDraw = 5 ; |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Orientations: 0th row, 0th column, EXIF orientation code, rotation 2x2 matrix that is opposite of orientation |
— | — | @@ -40,29 +40,29 @@ |
41 | 41 | * (we also would need a non-symmetric shape for the images to test those, like a letter F) |
42 | 42 | */ |
43 | 43 | private static $orientations = array( |
44 | | - array( |
45 | | - '0thRow' => 'top', |
46 | | - '0thCol' => 'left', |
47 | | - 'exifCode' => 1, |
48 | | - 'counterRotation' => array( array( 1, 0 ), array( 0, 1 ) ) |
| 44 | + array( |
| 45 | + '0thRow' => 'top', |
| 46 | + '0thCol' => 'left', |
| 47 | + 'exifCode' => 1, |
| 48 | + 'counterRotation' => array( array( 1, 0 ), array( 0, 1 ) ) |
49 | 49 | ), |
50 | | - array( |
| 50 | + array( |
51 | 51 | '0thRow' => 'bottom', |
52 | | - '0thCol' => 'right', |
53 | | - 'exifCode' => 3, |
54 | | - 'counterRotation' => array( array( -1, 0 ), array( 0, -1 ) ) |
| 52 | + '0thCol' => 'right', |
| 53 | + 'exifCode' => 3, |
| 54 | + 'counterRotation' => array( array( -1, 0 ), array( 0, -1 ) ) |
55 | 55 | ), |
56 | | - array( |
57 | | - '0thRow' => 'right', |
58 | | - '0thCol' => 'top', |
59 | | - 'exifCode' => 6, |
60 | | - 'counterRotation' => array( array( 0, 1 ), array( 1, 0 ) ) |
| 56 | + array( |
| 57 | + '0thRow' => 'right', |
| 58 | + '0thCol' => 'top', |
| 59 | + 'exifCode' => 6, |
| 60 | + 'counterRotation' => array( array( 0, 1 ), array( 1, 0 ) ) |
61 | 61 | ), |
62 | | - array( |
63 | | - '0thRow' => 'left', |
64 | | - '0thCol' => 'bottom', |
65 | | - 'exifCode' => 8, |
66 | | - 'counterRotation' => array( array( 0, -1 ), array( -1, 0 ) ) |
| 62 | + array( |
| 63 | + '0thRow' => 'left', |
| 64 | + '0thCol' => 'bottom', |
| 65 | + 'exifCode' => 8, |
| 66 | + 'counterRotation' => array( array( 0, -1 ), array( -1, 0 ) ) |
67 | 67 | ) |
68 | 68 | ); |
69 | 69 | |
— | — | @@ -76,10 +76,10 @@ |
77 | 77 | |
78 | 78 | // find the dictionary file, to generate random names |
79 | 79 | if ( !isset( $this->dictionaryFile ) ) { |
80 | | - foreach ( array( |
81 | | - '/usr/share/dict/words', |
82 | | - '/usr/dict/words', |
83 | | - dirname( __FILE__ ) . '/words.txt' ) |
| 80 | + foreach ( array( |
| 81 | + '/usr/share/dict/words', |
| 82 | + '/usr/dict/words', |
| 83 | + dirname( __FILE__ ) . '/words.txt' ) |
84 | 84 | as $dictionaryFile ) { |
85 | 85 | if ( is_file( $dictionaryFile ) and is_readable( $dictionaryFile ) ) { |
86 | 86 | $this->dictionaryFile = $dictionaryFile; |
— | — | @@ -116,7 +116,7 @@ |
117 | 117 | */ |
118 | 118 | function getImageWriteMethod( $format ) { |
119 | 119 | global $wgUseImageMagick, $wgImageMagickConvertCommand; |
120 | | - if ( $format === 'svg' ) { |
| 120 | + if ( $format === 'svg' ) { |
121 | 121 | return 'writeSvg'; |
122 | 122 | } else { |
123 | 123 | // figure out how to write images |
— | — | @@ -125,7 +125,7 @@ |
126 | 126 | return 'writeImageWithApi'; |
127 | 127 | } elseif ( $wgUseImageMagick && $wgImageMagickConvertCommand && is_executable( $wgImageMagickConvertCommand ) ) { |
128 | 128 | return 'writeImageWithCommandLine'; |
129 | | - } |
| 129 | + } |
130 | 130 | } |
131 | 131 | throw new Exception( "RandomImageGenerator: could not find a suitable method to write images in '$format' format" ); |
132 | 132 | } |
— | — | @@ -211,7 +211,7 @@ |
212 | 212 | */ |
213 | 213 | static function shapePointsToString( $shape ) { |
214 | 214 | $points = array(); |
215 | | - foreach ( $shape as $point ) { |
| 215 | + foreach ( $shape as $point ) { |
216 | 216 | $points[] = $point['x'] . ',' . $point['y']; |
217 | 217 | } |
218 | 218 | return join( " ", $points ); |
— | — | @@ -224,16 +224,16 @@ |
225 | 225 | * @param $format: file format to write (which is obviously always svg here) |
226 | 226 | * @param $filename: filename to write to |
227 | 227 | */ |
228 | | - public function writeSvg( $spec, $format, $filename ) { |
| 228 | + public function writeSvg( $spec, $format, $filename ) { |
229 | 229 | $svg = new SimpleXmlElement( '<svg/>' ); |
230 | 230 | $svg->addAttribute( 'xmlns', 'http://www.w3.org/2000/svg' ); |
231 | | - $svg->addAttribute( 'version', '1.1' ); |
232 | | - $svg->addAttribute( 'width', $spec['width'] ); |
233 | | - $svg->addAttribute( 'height', $spec['height'] ); |
| 231 | + $svg->addAttribute( 'version', '1.1' ); |
| 232 | + $svg->addAttribute( 'width', $spec['width'] ); |
| 233 | + $svg->addAttribute( 'height', $spec['height'] ); |
234 | 234 | $g = $svg->addChild( 'g' ); |
235 | 235 | foreach ( $spec['draws'] as $drawSpec ) { |
236 | 236 | $shape = $g->addChild( 'polygon' ); |
237 | | - $shape->addAttribute( 'fill', $drawSpec['fill'] ); |
| 237 | + $shape->addAttribute( 'fill', $drawSpec['fill'] ); |
238 | 238 | $shape->addAttribute( 'points', self::shapePointsToString( $drawSpec['shape'] ) ); |
239 | 239 | }; |
240 | 240 | if ( ! $fh = fopen( $filename, 'w' ) ) { |
— | — | @@ -252,20 +252,20 @@ |
253 | 253 | * @param $filename: filename to write to |
254 | 254 | */ |
255 | 255 | public function writeImageWithApi( $spec, $format, $filename ) { |
256 | | - // this is a hack because I can't get setImageOrientation() to work. See below. |
| 256 | + // this is a hack because I can't get setImageOrientation() to work. See below. |
257 | 257 | global $wgExiv2Command; |
258 | 258 | |
259 | 259 | $image = new Imagick(); |
260 | 260 | /** |
261 | | - * If the format is 'jpg', will also add a random orientation -- the image will be drawn rotated with triangle points |
| 261 | + * If the format is 'jpg', will also add a random orientation -- the image will be drawn rotated with triangle points |
262 | 262 | * facing in some direction (0, 90, 180 or 270 degrees) and a countering rotation should turn the triangle points upward again |
263 | 263 | */ |
264 | 264 | $orientation = self::$orientations[0]; // default is normal orientation |
265 | 265 | if ( $format == 'jpg' ) { |
266 | 266 | $orientation = self::$orientations[ array_rand( self::$orientations ) ]; |
267 | | - $spec = self::rotateImageSpec( $spec, $orientation['counterRotation'] ); |
| 267 | + $spec = self::rotateImageSpec( $spec, $orientation['counterRotation'] ); |
268 | 268 | } |
269 | | - |
| 269 | + |
270 | 270 | $image->newImage( $spec['width'], $spec['height'], new ImagickPixel( $spec['fill'] ) ); |
271 | 271 | |
272 | 272 | foreach ( $spec['draws'] as $drawSpec ) { |
— | — | @@ -288,7 +288,7 @@ |
289 | 289 | $cmd = wfEscapeShellArg( $wgExiv2Command ) |
290 | 290 | . " -M " |
291 | 291 | . wfEscapeShellArg( "set Exif.Image.Orientation " . $orientation['exifCode'] ) |
292 | | - . " " |
| 292 | + . " " |
293 | 293 | . wfEscapeShellArg( $filename ); |
294 | 294 | |
295 | 295 | $retval = 0; |
— | — | @@ -302,7 +302,7 @@ |
303 | 303 | /** |
304 | 304 | * Given an image specification, produce rotated version |
305 | 305 | * This is used when simulating a rotated image capture with EXIF orientation |
306 | | - * @param $spec Object returned by getImageSpec |
| 306 | + * @param $spec Object returned by getImageSpec |
307 | 307 | * @param $matrix 2x2 transformation matrix |
308 | 308 | * @return transformed Spec |
309 | 309 | */ |
— | — | @@ -313,8 +313,8 @@ |
314 | 314 | $correctionY = 0; |
315 | 315 | if ( $dims['x'] < 0 ) { |
316 | 316 | $correctionX = abs( $dims['x'] ); |
317 | | - } |
318 | | - if ( $dims['y'] < 0 ) { |
| 317 | + } |
| 318 | + if ( $dims['y'] < 0 ) { |
319 | 319 | $correctionY = abs( $dims['y'] ); |
320 | 320 | } |
321 | 321 | $tSpec['width'] = abs( $dims['x'] ); |
— | — | @@ -322,7 +322,7 @@ |
323 | 323 | $tSpec['fill'] = $spec['fill']; |
324 | 324 | $tSpec['draws'] = array(); |
325 | 325 | foreach( $spec['draws'] as $draw ) { |
326 | | - $tDraw = array( |
| 326 | + $tDraw = array( |
327 | 327 | 'fill' => $draw['fill'], |
328 | 328 | 'shape' => array() |
329 | 329 | ); |
— | — | @@ -339,13 +339,13 @@ |
340 | 340 | |
341 | 341 | /** |
342 | 342 | * Given a matrix and a pair of images, return new position |
343 | | - * @param $matrix: 2x2 rotation matrix |
| 343 | + * @param $matrix: 2x2 rotation matrix |
344 | 344 | * @param $x: x-coordinate number |
345 | 345 | * @param $y: y-coordinate number |
346 | | - * @return Array transformed with properties x, y |
| 346 | + * @return Array transformed with properties x, y |
347 | 347 | */ |
348 | 348 | private static function matrixMultiply2x2( $matrix, $x, $y ) { |
349 | | - return array( |
| 349 | + return array( |
350 | 350 | 'x' => $x * $matrix[0][0] + $y * $matrix[0][1], |
351 | 351 | 'y' => $x * $matrix[1][0] + $y * $matrix[1][1] |
352 | 352 | ); |
— | — | @@ -356,10 +356,10 @@ |
357 | 357 | * Based on an image specification, write such an image to disk, using the command line ImageMagick program ('convert'). |
358 | 358 | * |
359 | 359 | * Sample command line: |
360 | | - * $ convert -size 100x60 xc:rgb(90,87,45) \ |
361 | | - * -draw 'fill rgb(12,34,56) polygon 41,39 44,57 50,57 41,39' \ |
362 | | - * -draw 'fill rgb(99,123,231) circle 59,39 56,57' \ |
363 | | - * -draw 'fill rgb(240,12,32) circle 50,21 50,3' filename.png |
| 360 | + * $ convert -size 100x60 xc:rgb(90,87,45) \ |
| 361 | + * -draw 'fill rgb(12,34,56) polygon 41,39 44,57 50,57 41,39' \ |
| 362 | + * -draw 'fill rgb(99,123,231) circle 59,39 56,57' \ |
| 363 | + * -draw 'fill rgb(240,12,32) circle 50,21 50,3' filename.png |
364 | 364 | * |
365 | 365 | * @param $spec: spec describing background and shapes to draw |
366 | 366 | * @param $format: file format to write (unused by this method but kept so it has the same signature as writeImageWithApi) |