Ticket #26823: 26823.3.3.patch
File 26823.3.3.patch, 25.8 KB (added by , 11 years ago) |
---|
-
src/wp-includes/class-wp-image-editor-gd.php
140 140 * Resizes current image. 141 141 * Wraps _resize, since _resize returns a GD Resource. 142 142 * 143 * At minimum, either a height or width must be provided. 144 * If one of the two is set to null, the resize will 145 * maintain aspect ratio according to the provided dimension. 146 * 143 147 * @since 3.5.0 144 148 * @access public 145 149 * 146 * @param int $max_w147 * @param int $max_h150 * @param int|null $max_w Image Width 151 * @param int|null $max_h Image Height 148 152 * @param boolean $crop 149 153 * @return boolean|WP_Error 150 154 */ … … 192 196 * @param array $sizes { 193 197 * An array of image size arrays. Default sizes are 'small', 'medium', 'large'. 194 198 * 199 * Either a height or width must be provided. 200 * If one of the two is set to null, the resize will 201 * maintain aspect ratio according to the provided dimension. 202 * 195 203 * @type array $size { 196 * @type int $widthImage width.197 * @type int $heightImage height.198 * @type bool $cropOptional. Whether to crop the image. Default false.204 * @type int ['width'] Optional. Image width. 205 * @type int ['height'] Optional. Image height. 206 * @type bool ['crop'] Optional. Whether to crop the image. Default false. 199 207 * } 200 208 * } 201 * @return array An array of resized images metadata by size.209 * @return array An array of resized images' metadata by size. 202 210 */ 203 211 public function multi_resize( $sizes ) { 204 212 $metadata = array(); … … 205 213 $orig_size = $this->size; 206 214 207 215 foreach ( $sizes as $size => $size_data ) { 208 if ( ! ( isset( $size_data['width'] ) && isset( $size_data['height'] )) )216 if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) 209 217 continue; 210 218 219 if ( ! isset( $size_data['width'] ) ) 220 $size_data['width'] = null; 221 if ( ! isset( $size_data['height'] ) ) 222 $size_data['height'] = null; 223 211 224 if ( ! isset( $size_data['crop'] ) ) 212 225 $size_data['crop'] = false; 213 226 -
src/wp-includes/class-wp-image-editor-imagick.php
211 211 /** 212 212 * Resizes current image. 213 213 * 214 * At minimum, either a height or width must be provided. 215 * If one of the two is set to null, the resize will 216 * maintain aspect ratio according to the provided dimension. 217 * 214 218 * @since 3.5.0 215 219 * @access public 216 220 * 217 * @param int $max_w218 * @param int $max_h221 * @param int|null $max_w Image Width 222 * @param int|null $max_h Image Height 219 223 * @param boolean $crop 220 224 * @return boolean|WP_Error 221 225 */ … … 255 259 * @param array $sizes { 256 260 * An array of image size arrays. Default sizes are 'small', 'medium', 'large'. 257 261 * 262 * Either a height or width must be provided. 263 * If one of the two is set to null, the resize will 264 * maintain aspect ratio according to the provided dimension. 265 * 258 266 * @type array $size { 259 * @type int $widthImage width.260 * @type int $heightImage height.267 * @type int ['width'] Optional. Image width. 268 * @type int ['height'] Optional. Image height. 261 269 * @type bool $crop Optional. Whether to crop the image. Default false. 262 270 * } 263 271 * } 264 * @return array An array of resized images metadata by size.272 * @return array An array of resized images' metadata by size. 265 273 */ 266 274 public function multi_resize( $sizes ) { 267 275 $metadata = array(); … … 272 280 if ( ! $this->image ) 273 281 $this->image = $orig_image->getImage(); 274 282 275 if ( ! ( isset( $size_data['width'] ) && isset( $size_data['height'] )) )283 if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) 276 284 continue; 277 285 286 if ( ! isset( $size_data['width'] ) ) 287 $size_data['width'] = null; 288 if ( ! isset( $size_data['height'] ) ) 289 $size_data['height'] = null; 290 291 278 292 if ( ! isset( $size_data['crop'] ) ) 279 293 $size_data['crop'] = false; 280 294 -
tests/phpunit/tests/image/editor_gd.php
13 13 public function setup() { 14 14 require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' ); 15 15 require_once( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' ); 16 17 $editor = new WP_Image_Editor_GD( null ); 18 19 if ( ! $editor->test() ) 20 $this->markTestSkipped( 'Image GD not available' ); 21 22 16 23 parent::setUp(); 17 24 } 18 25 26 public function tearDown() { 27 $folder = DIR_TESTDATA . '/images/waffles-*.jpg'; 28 29 foreach (glob($folder) as $file) { 30 unlink($file); 31 } 32 33 } 34 19 35 /** 36 * Helper function to check actual image dimensions on disk 37 * 38 * @access private 39 * 40 * @param string Image Filename 41 * @param int Width to Check 42 * @param int Height to Check 43 */ 44 private function check_image_dimensions( $filename, $width, $height ) { 45 # Now, verify real dimensions are as expected 46 $image = new WP_Image_Editor_GD( $filename ); 47 $image->load(); 48 49 $this->assertEquals( 50 array( 51 'width' => $width, 52 'height' => $height, 53 ), 54 $image->get_size() 55 ); 56 } 57 58 /** 20 59 * Check support for GD compatible mime types. 21 *22 60 */ 23 61 public function test_supports_mime_type() { 24 62 $gd_image_editor = new WP_Image_Editor_GD( null ); … … 30 68 31 69 /** 32 70 * Test resizing an image, not using crop 33 *34 71 */ 35 72 public function test_resize() { 73 $file = DIR_TESTDATA . '/images/waffles.jpg'; 36 74 37 $file = DIR_TESTDATA . '/images/gradient-square.jpg';38 39 75 $gd_image_editor = new WP_Image_Editor_GD( $file ); 40 76 $gd_image_editor->load(); 41 77 42 78 $gd_image_editor->resize( 100, 50 ); 43 79 44 $this->assertEquals( array( 'width' => 50, 'height' => 50 ), $gd_image_editor->get_size() ); 80 $this->assertEquals( 81 array( 82 'width' => 75, 83 'height' => 50, 84 ), 85 $gd_image_editor->get_size() 86 ); 45 87 } 46 88 47 89 /** 48 * Test resizing an image including cropping 49 * 90 * Test multi_resize with single image resize and no crop 50 91 */ 51 public function test_resize_and_crop() { 92 public function test_single_multi_resize() { 93 $file = DIR_TESTDATA . '/images/waffles.jpg'; 52 94 53 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 95 $gd_image_editor = new WP_Image_Editor_GD( $file ); 96 $gd_image_editor->load(); 54 97 98 $sizes_array = array( 99 array( 100 'width' => 50, 101 'height' => 50, 102 ), 103 ); 104 105 $resized = $gd_image_editor->multi_resize( $sizes_array ); 106 107 # First, check to see if returned array is as expected 108 $expected_array = array( 109 array( 110 'file' => 'waffles-50x33.jpg', 111 'width' => 50, 112 'height' => 33, 113 'mime-type' => 'image/jpeg', 114 ), 115 ); 116 117 $this->assertEquals( $expected_array, $resized ); 118 119 // Now, verify real dimensions are as expected 120 $image_path = DIR_TESTDATA . '/images/'. $resized[0]['file']; 121 $this->check_image_dimensions( 122 $image_path, 123 $expected_array[0]['width'], 124 $expected_array[0]['height'] 125 ); 126 127 128 } 129 130 /** 131 * Test multi_resize doesn't create an image as both H and W are null or 0 132 */ 133 public function test_multi_resize_does_not_create() { 134 $file = DIR_TESTDATA . '/images/waffles.jpg'; 135 55 136 $gd_image_editor = new WP_Image_Editor_GD( $file ); 56 137 $gd_image_editor->load(); 57 138 139 $sizes_array = array( 140 /** 141 * #1 - 142 * no output 143 */ 144 array( 145 'width' => 0, # Zero Value 146 'height' => 0, # Zero Value 147 ), 148 /** 149 * #2 - 150 * no output 151 */ 152 array( 153 'width' => 0, # Zero Value 154 'height' => 0, # Zero Value 155 'crop' => true, 156 ), 157 /** 158 * #3 - 159 * no output 160 */ 161 array( 162 'width' => null, # null Value 163 'height' => null, # null Value 164 ), 165 /** 166 * #4 - 167 * no output 168 */ 169 array( 170 'width' => null, # null Value 171 'height' => null, # null Value 172 'crop' => true, 173 ), 174 /** 175 * #5 - 176 * no output 177 */ 178 array( 179 'width' => '', # missing Value 180 'height' => '', # missing Value 181 ), 182 /** 183 * #6 - 184 * no output 185 */ 186 array( 187 'width' => '', # missing Value 188 'height' => '', # missing Value 189 'crop' => true, 190 ), 191 /** 192 * #7 - 193 * no output 194 */ 195 array( 196 'width' => 0, # Zero Value and missing height Value 197 ), 198 /** 199 * #8 - 200 * no output 201 */ 202 array( 203 'width' => 0, # Zero Value and missing height Value 204 'crop' => true, 205 ), 206 /** 207 * #9 - 208 * no output 209 */ 210 array( 211 'width' => null, # null Value and missing height Value 212 ), 213 /** 214 * #10 - 215 * no output 216 */ 217 array( 218 'width' => null, # null Value and missing height Value 219 'crop' => true, 220 ), 221 222 /** 223 * 11 - 224 * no output 225 */ 226 array( 227 'width' => '', # missing Value and missing height Value 228 ), 229 /** 230 * #12 - 231 * no output 232 */ 233 array( 234 'width' => '', # missing Value and missing height Value 235 'crop' => true, 236 ), 237 ); 238 239 240 // run function 241 $resized = $gd_image_editor->multi_resize( $sizes_array ); 242 243 // reurn an empty array 244 $this->assertEmpty($resized); 245 246 } 247 248 249 250 /** 251 * Test multi_resize with multiple sizes 252 * 253 * @ticket 26823 254 */ 255 public function test_multi_resize() { 256 $file = DIR_TESTDATA . '/images/waffles.jpg'; 257 258 $gd_image_editor = new WP_Image_Editor_GD( $file ); 259 $gd_image_editor->load(); 260 261 $sizes_array = array( 262 263 /** 264 * #0 - 10x10 resize, no cropping. 265 * By aspect, should be 10x6 output. 266 */ 267 array( 268 'width' => 10, 269 'height' => 10, 270 'crop' => false, 271 ), 272 273 /** 274 * #1 - 75x50 resize, with cropping. 275 * Output dimensions should be 75x50 276 */ 277 array( 278 'width' => 75, 279 'height' => 50, 280 'crop' => true, 281 ), 282 283 /** 284 * #2 - 20 pixel max height, no cropping. 285 * By aspect, should be 30x20 output. 286 */ 287 array( 288 'width' => 9999, # Arbitrary High Value 289 'height' => 20, 290 'crop' => false, 291 ), 292 293 /** 294 * #3 - 45 pixel max height, with cropping. 295 * By aspect, should be 45x400 output. 296 */ 297 array( 298 'width' => 45, 299 'height' => 9999, # Arbitrary High Value 300 'crop' => true, 301 ), 302 303 /** 304 * #4 - 50 pixel max width, no cropping. 305 * By aspect, should be 50x33 output. 306 */ 307 array( 308 'width' => 50, 309 ), 310 311 /** 312 * #5 - 55 pixel max width, no cropping, null height 313 * By aspect, should be 55x36 output. 314 */ 315 array( 316 'width' => 55, 317 'height' => null, 318 ), 319 320 /** 321 * #6 - 55 pixel max height, no cropping, no width specified. 322 * By aspect, should be 82x55 output. 323 */ 324 array( 325 'height' => 55, 326 ), 327 328 /** 329 * #7 - 60 pixel max height, no cropping, null width. 330 * By aspect, should be 90x60 output. 331 */ 332 array( 333 'width' => null, 334 'height' => 60, 335 ), 336 337 /** 338 * #8 - 70 pixel max height, no cropping, negative width. 339 * By aspect, should be 105x70 output. 340 */ 341 array( 342 'width' => -9999, # Arbitrary Negative Value 343 'height' => 70, 344 ), 345 346 /** 347 * #9 - 200 pixel max width, no cropping, negative height. 348 * By aspect, should be 200x133 output. 349 */ 350 array( 351 'width' => 200, 352 'height' => -9999, # Arbitrary Negative Value 353 ), 354 /** 355 * #10 - 55 pixel max width, no cropping, '' height 356 * By aspect, should be 65x36 output. 357 */ 358 array( 359 'width' => 65, 360 'height' => '', 361 ), 362 363 ); 364 365 $resized = $gd_image_editor->multi_resize( $sizes_array ); 366 367 $expected_array = array( 368 369 // #0 370 array( 371 'file' => 'waffles-10x6.jpg', 372 'width' => 10, 373 'height' => 6, 374 'mime-type' => 'image/jpeg', 375 ), 376 377 // #1 378 array( 379 'file' => 'waffles-75x50.jpg', 380 'width' => 75, 381 'height' => 50, 382 'mime-type' => 'image/jpeg', 383 ), 384 385 // #2 386 array( 387 'file' => 'waffles-30x20.jpg', 388 'width' => 30, 389 'height' => 20, 390 'mime-type' => 'image/jpeg', 391 ), 392 393 // #3 394 array( 395 'file' => 'waffles-45x400.jpg', 396 'width' => 45, 397 'height' => 400, 398 'mime-type' => 'image/jpeg', 399 ), 400 401 // #4 402 array( 403 'file' => 'waffles-50x33.jpg', 404 'width' => 50, 405 'height' => 33, 406 'mime-type' => 'image/jpeg', 407 ), 408 409 // #5 410 array( 411 'file' => 'waffles-55x36.jpg', 412 'width' => 55, 413 'height' => 36, 414 'mime-type' => 'image/jpeg', 415 ), 416 417 // #6 418 array( 419 'file' => 'waffles-82x55.jpg', 420 'width' => 82, 421 'height' => 55, 422 'mime-type' => 'image/jpeg', 423 ), 424 425 // #7 426 array( 427 'file' => 'waffles-90x60.jpg', 428 'width' => 90, 429 'height' => 60, 430 'mime-type' => 'image/jpeg', 431 ), 432 433 // #8 434 array( 435 'file' => 'waffles-105x70.jpg', 436 'width' => 105, 437 'height' => 70, 438 'mime-type' => 'image/jpeg', 439 ), 440 441 // #9 442 array( 443 'file' => 'waffles-200x133.jpg', 444 'width' => 200, 445 'height' => 133, 446 'mime-type' => 'image/jpeg', 447 ), 448 449 // #10 450 array( 451 'file' => 'waffles-65x43.jpg', 452 'width' => 65, 453 'height' => 43, 454 'mime-type' => 'image/jpeg', 455 ), 456 ); 457 458 $this->assertNotNull( $resized ); 459 $this->assertEquals( $expected_array, $resized ); 460 461 foreach( $resized as $key => $image_data ){ 462 $image_path = DIR_TESTDATA . '/images/' . $image_data['file']; 463 464 // Now, verify real dimensions are as expected 465 $this->check_image_dimensions( 466 $image_path, 467 $expected_array[$key]['width'], 468 $expected_array[$key]['height'] 469 ); 470 471 // Remove temporary file 472 473 } 474 } 475 476 /** 477 * Test resizing an image with cropping 478 */ 479 public function test_resize_and_crop() { 480 $file = DIR_TESTDATA . '/images/waffles.jpg'; 481 482 $gd_image_editor = new WP_Image_Editor_GD( $file ); 483 $gd_image_editor->load(); 484 58 485 $gd_image_editor->resize( 100, 50, true ); 59 486 60 $this->assertEquals( array( 'width' => 100, 'height' => 50 ), $gd_image_editor->get_size() ); 487 $this->assertEquals( 488 array( 489 'width' => 100, 490 'height' => 50, 491 ), 492 $gd_image_editor->get_size() 493 ); 61 494 } 62 495 63 496 /** … … 64 497 * Test cropping an image 65 498 */ 66 499 public function test_crop() { 500 $file = DIR_TESTDATA . '/images/waffles.jpg'; 67 501 68 $file = DIR_TESTDATA . '/images/gradient-square.jpg';69 70 502 $gd_image_editor = new WP_Image_Editor_GD( $file ); 71 503 $gd_image_editor->load(); 72 504 73 505 $gd_image_editor->crop( 0, 0, 50, 50 ); 74 506 75 $this->assertEquals( array( 'width' => 50, 'height' => 50 ), $gd_image_editor->get_size() ); 507 $this->assertEquals( 508 array( 509 'width' => 50, 510 'height' => 50, 511 ), 512 $gd_image_editor->get_size() 513 ); 76 514 77 515 } 78 516 … … 80 518 * Test rotating an image 180 deg 81 519 */ 82 520 public function test_rotate() { 83 84 521 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 85 522 86 523 $gd_image_editor = new WP_Image_Editor_GD( $file ); … … 100 537 * Test flipping an image 101 538 */ 102 539 public function test_flip() { 103 104 540 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 105 541 106 542 $gd_image_editor = new WP_Image_Editor_GD( $file ); … … 122 558 * @ticket 23039 123 559 */ 124 560 public function test_image_preserves_alpha_on_resize() { 125 126 561 $file = DIR_TESTDATA . '/images/transparent.png'; 127 562 128 563 $editor = wp_get_image_editor( $file ); … … 142 577 * @ticket 23039 143 578 */ 144 579 public function test_image_preserves_alpha() { 145 146 580 $file = DIR_TESTDATA . '/images/transparent.png'; 147 581 148 582 $editor = wp_get_image_editor( $file ); -
tests/phpunit/tests/image/editor_imagick.php
23 23 parent::setUp(); 24 24 } 25 25 26 27 public function tearDown() { 28 $folder = DIR_TESTDATA . '/images/waffles-*.jpg'; 29 30 foreach (glob($folder) as $file) { 31 unlink($file); 32 } 33 34 } 35 36 26 37 /** 38 * Helper function to check actual image dimensions on disk 39 * 40 * @access private 41 * 42 * @param string Image Filename 43 * @param int Width to Check 44 * @param int Height to Check 45 */ 46 private function check_image_dimensions( $filename, $width, $height ) { 47 $imagick_image_editor = new WP_Image_Editor_Imagick( $filename ); 48 $imagick_image_editor->load(); 49 50 $this->assertEquals( 51 array( 52 'width' => $width, 53 'height' => $height, 54 ), 55 $imagick_image_editor->get_size() 56 ); 57 } 58 59 /** 27 60 * Check support for Image Magick compatible mime types. 28 *29 61 */ 30 62 public function test_supports_mime_type() { 31 63 … … 38 70 39 71 /** 40 72 * Test resizing an image, not using crop 41 *42 73 */ 43 74 public function test_resize() { 75 $file = DIR_TESTDATA . '/images/waffles.jpg'; 44 76 45 $file = DIR_TESTDATA . '/images/gradient-square.jpg';46 47 77 $imagick_image_editor = new WP_Image_Editor_Imagick( $file ); 48 78 $imagick_image_editor->load(); 49 79 50 80 $imagick_image_editor->resize( 100, 50 ); 51 81 52 $this->assertEquals( array( 'width' => 50, 'height' => 50 ), $imagick_image_editor->get_size() ); 82 $this->assertEquals( 83 array( 84 'width' => 75, 85 'height' => 50, 86 ), 87 $imagick_image_editor->get_size() 88 ); 89 53 90 } 54 91 55 92 /** 56 * Test resizing an image including cropping 57 * 93 * Test multi_resize with single image resize and no crop 58 94 */ 59 public function test_resize_and_crop() { 95 public function test_single_multi_resize() { 96 $file = DIR_TESTDATA . '/images/waffles.jpg'; 60 97 61 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 98 $test_image = new WP_Image_Editor_Imagick( $file ); 99 $test_image->load(); 62 100 101 $sizes_array = array( 102 array( 103 'width' => 50, 104 'height' => 50, 105 ), 106 ); 107 108 $resized = $test_image->multi_resize( $sizes_array ); 109 110 # First, check to see if returned array is as expected 111 $expected_array = array( 112 array( 113 'file' => 'waffles-50x33.jpg', 114 'width' => 50, 115 'height' => 33, 116 'mime-type' => 'image/jpeg', 117 ), 118 ); 119 120 $this->assertEquals( $expected_array, $resized ); 121 122 // Now, verify real dimensions are as expected 123 $image_path = DIR_TESTDATA . '/images/'. $resized[0]['file']; 124 $this->check_image_dimensions( 125 $image_path, 126 $expected_array[0]['width'], 127 $expected_array[0]['height'] 128 ); 129 130 131 } 132 133 /** 134 * Test multi_resize doesn't create an image as both H and W are null or 0 135 */ 136 public function test_multi_resize_does_not_create() { 137 $file = DIR_TESTDATA . '/images/waffles.jpg'; 138 139 $gd_image_editor = new WP_Image_Editor_Imagick( $file ); 140 $gd_image_editor->load(); 141 142 $sizes_array = array( 143 /** 144 * #1 - 145 * no output 146 */ 147 array( 148 'width' => 0, # Zero Value 149 'height' => 0, # Zero Value 150 ), 151 /** 152 * #2 - 153 * no output 154 */ 155 array( 156 'width' => 0, # Zero Value 157 'height' => 0, # Zero Value 158 'crop' => true, 159 ), 160 /** 161 * #3 - 162 * no output 163 */ 164 array( 165 'width' => null, # null Value 166 'height' => null, # null Value 167 ), 168 /** 169 * #4 - 170 * no output 171 */ 172 array( 173 'width' => null, # null Value 174 'height' => null, # null Value 175 'crop' => true, 176 ), 177 /** 178 * #5 - 179 * no output 180 */ 181 array( 182 'width' => '', # missing Value 183 'height' => '', # missing Value 184 ), 185 /** 186 * #6 - 187 * no output 188 */ 189 array( 190 'width' => '', # missing Value 191 'height' => '', # missing Value 192 'crop' => true, 193 ), 194 /** 195 * #7 - 196 * no output 197 */ 198 array( 199 'width' => 0, # Zero Value and missing height Value 200 ), 201 /** 202 * #8 - 203 * no output 204 */ 205 array( 206 'width' => 0, # Zero Value and missing height Value 207 'crop' => true, 208 ), 209 /** 210 * #9 - 211 * no output 212 */ 213 array( 214 'width' => null, # null Value and missing height Value 215 ), 216 /** 217 * #10 - 218 * no output 219 */ 220 array( 221 'width' => null, # null Value and missing height Value 222 'crop' => true, 223 ), 224 225 /** 226 * 11 - 227 * no output 228 */ 229 array( 230 'width' => '', # missing Value and missing height Value 231 ), 232 /** 233 * #12 - 234 * no output 235 */ 236 array( 237 'width' => '', # missing Value and missing height Value 238 'crop' => true, 239 ), 240 ); 241 242 243 // run function 244 $resized = $gd_image_editor->multi_resize( $sizes_array ); 245 246 // reurn an empty array 247 $this->assertEmpty($resized); 248 249 } 250 251 /** 252 * Test multi_resize with multiple sizes 253 * 254 * @ticket 26823 255 */ 256 public function test_multi_resize() { 257 $file = DIR_TESTDATA . '/images/waffles.jpg'; 258 63 259 $imagick_image_editor = new WP_Image_Editor_Imagick( $file ); 64 260 $imagick_image_editor->load(); 65 261 66 $ imagick_image_editor->resize( 100, 50, true );262 $sizes_array = array( 67 263 68 $this->assertEquals( array( 'width' => 100, 'height' => 50 ), $imagick_image_editor->get_size() ); 264 /** 265 * #0 - 10x10 resize, no cropping. 266 * By aspect, should be 10x6 output. 267 */ 268 array( 269 'width' => 10, 270 'height' => 10, 271 'crop' => false, 272 ), 273 274 /** 275 * #1 - 75x50 resize, with cropping. 276 * Output dimensions should be 75x50 277 */ 278 array( 279 'width' => 75, 280 'height' => 50, 281 'crop' => true, 282 ), 283 284 /** 285 * #2 - 20 pixel max height, no cropping. 286 * By aspect, should be 30x20 output. 287 */ 288 array( 289 'width' => 9999, # Arbitrary High Value 290 'height' => 20, 291 'crop' => false, 292 ), 293 294 /** 295 * #3 - 45 pixel max height, with cropping. 296 * By aspect, should be 45x400 output. 297 */ 298 array( 299 'width' => 45, 300 'height' => 9999, # Arbitrary High Value 301 'crop' => true, 302 ), 303 304 /** 305 * #4 - 50 pixel max width, no cropping. 306 * By aspect, should be 50x33 output. 307 */ 308 array( 309 'width' => 50, 310 ), 311 312 /** 313 * #5 - 55 pixel max width, no cropping, null height 314 * By aspect, should be 55x36 output. 315 */ 316 array( 317 'width' => 55, 318 'height' => null, 319 ), 320 321 /** 322 * #6 - 55 pixel max height, no cropping, no width specified. 323 * By aspect, should be 82x55 output. 324 */ 325 array( 326 'height' => 55, 327 ), 328 329 /** 330 * #7 - 60 pixel max height, no cropping, null width. 331 * By aspect, should be 90x60 output. 332 */ 333 array( 334 'width' => null, 335 'height' => 60, 336 ), 337 338 /** 339 * #8 - 70 pixel max height, no cropping, negative width. 340 * By aspect, should be 105x70 output. 341 */ 342 array( 343 'width' => -9999, # Arbitrary Negative Value 344 'height' => 70, 345 ), 346 347 /** 348 * #9 - 200 pixel max width, no cropping, negative height. 349 * By aspect, should be 200x133 output. 350 */ 351 array( 352 'width' => 200, 353 'height' => -9999, # Arbitrary Negative Value 354 ), 355 /** 356 * #10 - 55 pixel max width, no cropping, '' height 357 * By aspect, should be 65x36 output. 358 */ 359 array( 360 'width' => 65, 361 'height' => '', 362 ), 363 364 ); 365 366 $resized = $imagick_image_editor->multi_resize( $sizes_array ); 367 368 $expected_array = array( 369 370 // #0 371 array( 372 'file' => 'waffles-10x6.jpg', 373 'width' => 10, 374 'height' => 6, 375 'mime-type' => 'image/jpeg', 376 ), 377 378 // #1 379 array( 380 'file' => 'waffles-75x50.jpg', 381 'width' => 75, 382 'height' => 50, 383 'mime-type' => 'image/jpeg', 384 ), 385 386 // #2 387 array( 388 'file' => 'waffles-30x20.jpg', 389 'width' => 30, 390 'height' => 20, 391 'mime-type' => 'image/jpeg', 392 ), 393 394 // #3 395 array( 396 'file' => 'waffles-45x400.jpg', 397 'width' => 45, 398 'height' => 400, 399 'mime-type' => 'image/jpeg', 400 ), 401 402 // #4 403 array( 404 'file' => 'waffles-50x33.jpg', 405 'width' => 50, 406 'height' => 33, 407 'mime-type' => 'image/jpeg', 408 ), 409 410 // #5 411 array( 412 'file' => 'waffles-55x36.jpg', 413 'width' => 55, 414 'height' => 36, 415 'mime-type' => 'image/jpeg', 416 ), 417 418 // #6 419 array( 420 'file' => 'waffles-82x55.jpg', 421 'width' => 82, 422 'height' => 55, 423 'mime-type' => 'image/jpeg', 424 ), 425 426 // #7 427 array( 428 'file' => 'waffles-90x60.jpg', 429 'width' => 90, 430 'height' => 60, 431 'mime-type' => 'image/jpeg', 432 ), 433 434 // #8 435 array( 436 'file' => 'waffles-105x70.jpg', 437 'width' => 105, 438 'height' => 70, 439 'mime-type' => 'image/jpeg', 440 ), 441 442 // #9 443 array( 444 'file' => 'waffles-200x133.jpg', 445 'width' => 200, 446 'height' => 133, 447 'mime-type' => 'image/jpeg', 448 ), 449 450 // #10 451 array( 452 'file' => 'waffles-65x43.jpg', 453 'width' => 65, 454 'height' => 43, 455 'mime-type' => 'image/jpeg', 456 ), 457 ); 458 459 $this->assertNotNull( $resized ); 460 $this->assertEquals( $expected_array, $resized ); 461 462 foreach( $resized as $key => $image_data ){ 463 $image_path = DIR_TESTDATA . '/images/' . $image_data['file']; 464 465 // Now, verify real dimensions are as expected 466 $this->check_image_dimensions( 467 $image_path, 468 $expected_array[$key]['width'], 469 $expected_array[$key]['height'] 470 ); 471 472 } 69 473 } 70 474 71 475 /** … … 73 477 */ 74 478 public function test_crop() { 75 479 76 $file = DIR_TESTDATA . '/images/ gradient-square.jpg';480 $file = DIR_TESTDATA . '/images/waffles.jpg'; 77 481 78 482 $imagick_image_editor = new WP_Image_Editor_Imagick( $file ); 79 483 $imagick_image_editor->load(); … … 89 493 */ 90 494 public function test_rotate() { 91 495 92 $file = DIR_TESTDATA . '/images/ gradient-square.jpg';496 $file = DIR_TESTDATA . '/images/waffles.jpg'; 93 497 94 498 $imagick_image_editor = new WP_Image_Editor_Imagick( $file ); 95 499 $imagick_image_editor->load();