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