Ticket #18532: 18532k.diff
File 18532k.diff, 15.8 KB (added by , 10 years ago) |
---|
-
tests/phpunit/tests/image/editor_imagick.php
282 282 283 283 // #0 284 284 array( 285 'file' => 'waffles-10x 6.jpg',285 'file' => 'waffles-10x7.jpg', 286 286 'width' => 10, 287 'height' => 6,287 'height' => 7, 288 288 'mime-type' => 'image/jpeg', 289 289 ), 290 290 … … 322 322 323 323 // #5 324 324 array( 325 'file' => 'waffles-55x3 6.jpg',325 'file' => 'waffles-55x37.jpg', 326 326 'width' => 55, 327 'height' => 3 6,327 'height' => 37, 328 328 'mime-type' => 'image/jpeg', 329 329 ), 330 330 331 331 // #6 332 332 array( 333 'file' => 'waffles-8 2x55.jpg',334 'width' => 8 2,333 'file' => 'waffles-83x55.jpg', 334 'width' => 83, 335 335 'height' => 55, 336 336 'mime-type' => 'image/jpeg', 337 337 ), -
tests/phpunit/tests/image/size.php
13 13 14 14 // no constraint - should have no effect 15 15 $out = wp_constrain_dimensions(640, 480, 0, 0); 16 $this->assert Equals(array(640, 480), $out);16 $this->assertSame(array(640, 480), $out); 17 17 18 18 $out = wp_constrain_dimensions(640, 480); 19 $this->assert Equals(array(640, 480), $out);19 $this->assertSame(array(640, 480), $out); 20 20 21 21 $out = wp_constrain_dimensions(0, 0, 0, 0); 22 $this->assertEquals(array(0, 0), $out); 22 $this->assertSame(array(0, 0), $out); 23 24 $out = wp_constrain_dimensions(465, 700, 177, 177); 25 $this->assertSame(array(118, 177), $out); 23 26 } 24 27 25 28 function test_constrain_dims_smaller() { … … 28 31 29 32 // image size is smaller than the constraint - no effect 30 33 $out = wp_constrain_dimensions(500, 600, 1024, 768); 31 $this->assert Equals(array(500, 600), $out);34 $this->assertSame(array(500, 600), $out); 32 35 33 36 $out = wp_constrain_dimensions(500, 600, 0, 768); 34 $this->assert Equals(array(500, 600), $out);37 $this->assertSame(array(500, 600), $out); 35 38 36 39 $out = wp_constrain_dimensions(500, 600, 1024, 0); 37 $this->assert Equals(array(500, 600), $out);40 $this->assertSame(array(500, 600), $out); 38 41 } 39 42 40 43 function test_constrain_dims_equal() { … … 43 46 44 47 // image size is equal to the constraint - no effect 45 48 $out = wp_constrain_dimensions(1024, 768, 1024, 768); 46 $this->assert equals(array(1024, 768), $out);49 $this->assertSame(array(1024, 768), $out); 47 50 48 51 $out = wp_constrain_dimensions(1024, 768, 0, 768); 49 $this->assert equals(array(1024, 768), $out);52 $this->assertSame(array(1024, 768), $out); 50 53 51 54 $out = wp_constrain_dimensions(1024, 768, 1024, 0); 52 $this->assert equals(array(1024, 768), $out);55 $this->assertSame(array(1024, 768), $out); 53 56 } 54 57 55 58 function test_constrain_dims_larger() { … … 58 61 59 62 // image size is larger than the constraint - result should be constrained 60 63 $out = wp_constrain_dimensions(1024, 768, 500, 600); 61 $this->assert equals(array(500, 375), $out);64 $this->assertSame(array(500, 375), $out); 62 65 63 66 $out = wp_constrain_dimensions(1024, 768, 0, 600); 64 $this->assert equals(array(800, 600), $out);67 $this->assertSame(array(800, 600), $out); 65 68 66 69 $out = wp_constrain_dimensions(1024, 768, 500, 0); 67 $this->assert equals(array(500, 375), $out);70 $this->assertSame(array(500, 375), $out); 68 71 69 72 // also try a portrait oriented image 70 73 $out = wp_constrain_dimensions(300, 800, 500, 600); 71 $this->assert equals(array(225, 600), $out);74 $this->assertSame(array(225, 600), $out); 72 75 73 76 $out = wp_constrain_dimensions(300, 800, 0, 600); 74 $this->assert equals(array(225, 600), $out);77 $this->assertSame(array(225, 600), $out); 75 78 76 79 $out = wp_constrain_dimensions(300, 800, 200, 0); 77 $this->assert equals(array(200, 533), $out);80 $this->assertSame(array(200, 533), $out); 78 81 } 79 82 80 83 function test_constrain_dims_boundary() { … … 83 86 84 87 // one dimension is larger than the constraint, one smaller - result should be constrained 85 88 $out = wp_constrain_dimensions(1024, 768, 500, 800); 86 $this->assert equals(array(500, 375), $out);89 $this->assertSame(array(500, 375), $out); 87 90 88 91 $out = wp_constrain_dimensions(1024, 768, 2000, 700); 89 $this->assert equals(array(933, 700), $out);92 $this->assertSame(array(933, 700), $out); 90 93 91 94 // portrait 92 95 $out = wp_constrain_dimensions(768, 1024, 800, 500); 93 $this->assert equals(array(375, 500), $out);96 $this->assertSame(array(375, 500), $out); 94 97 95 98 $out = wp_constrain_dimensions(768, 1024, 2000, 700); 96 $this->assert equals(array(525, 700), $out);99 $this->assertSame(array(525, 700), $out); 97 100 } 98 101 99 102 /** … … 101 104 */ 102 105 function test_shrink_dimensions_default() { 103 106 $out = wp_shrink_dimensions(640, 480); 104 $this->assert Equals(array(128, 96), $out);107 $this->assertSame(array(128, 96), $out); 105 108 106 109 $out = wp_shrink_dimensions(480, 640); 107 $this->assert Equals(array(72, 96), $out);110 $this->assertSame(array(72, 96), $out); 108 111 } 109 112 110 113 /** … … 113 116 function test_shrink_dimensions_smaller() { 114 117 // image size is smaller than the constraint - no effect 115 118 $out = wp_shrink_dimensions(500, 600, 1024, 768); 116 $this->assert Equals(array(500, 600), $out);119 $this->assertSame(array(500, 600), $out); 117 120 118 121 $out = wp_shrink_dimensions(600, 500, 1024, 768); 119 $this->assert Equals(array(600, 500), $out);122 $this->assertSame(array(600, 500), $out); 120 123 } 121 124 122 125 /** … … 125 128 function test_shrink_dimensions_equal() { 126 129 // image size is equal to the constraint - no effect 127 130 $out = wp_shrink_dimensions(500, 600, 500, 600); 128 $this->assert Equals(array(500, 600), $out);131 $this->assertSame(array(500, 600), $out); 129 132 130 133 $out = wp_shrink_dimensions(600, 500, 600, 500); 131 $this->assert Equals(array(600, 500), $out);134 $this->assertSame(array(600, 500), $out); 132 135 } 133 136 134 137 /** … … 137 140 function test_shrink_dimensions_larger() { 138 141 // image size is larger than the constraint - result should be constrained 139 142 $out = wp_shrink_dimensions(1024, 768, 500, 600); 140 $this->assert equals(array(500, 375), $out);143 $this->assertSame(array(500, 375), $out); 141 144 142 145 $out = wp_shrink_dimensions(300, 800, 500, 600); 143 $this->assert equals(array(225, 600), $out);146 $this->assertSame(array(225, 600), $out); 144 147 } 145 148 146 149 /** … … 149 152 function test_shrink_dimensions_boundary() { 150 153 // one dimension is larger than the constraint, one smaller - result should be constrained 151 154 $out = wp_shrink_dimensions(1024, 768, 500, 800); 152 $this->assert equals(array(500, 375), $out);155 $this->assertSame(array(500, 375), $out); 153 156 154 157 $out = wp_shrink_dimensions(1024, 768, 2000, 700); 155 $this->assert equals(array(933, 700), $out);158 $this->assertSame(array(933, 700), $out); 156 159 157 160 // portrait 158 161 $out = wp_shrink_dimensions(768, 1024, 800, 500); 159 $this->assert equals(array(375, 500), $out);162 $this->assertSame(array(375, 500), $out); 160 163 161 164 $out = wp_shrink_dimensions(768, 1024, 2000, 700); 162 $this->assert equals(array(525, 700), $out);165 $this->assertSame(array(525, 700), $out); 163 166 } 164 167 165 168 function test_constrain_size_for_editor_thumb() { 166 169 $out = image_constrain_size_for_editor(600, 400, 'thumb'); 167 $this->assert Equals(array(150, 100), $out);170 $this->assertSame(array(150, 100), $out); 168 171 169 172 $out = image_constrain_size_for_editor(64, 64, 'thumb'); 170 $this->assert Equals(array(64, 64), $out);173 $this->assertSame(array(64, 64), $out); 171 174 } 172 175 173 176 function test_constrain_size_for_editor_medium() { … … 181 184 update_option('medium_size_h', 0); 182 185 183 186 $out = image_constrain_size_for_editor(600, 400, 'medium'); 184 $this->assert Equals(array(500, 333), $out);187 $this->assertSame(array(500, 333), $out); 185 188 186 189 $out = image_constrain_size_for_editor(400, 600, 'medium'); 187 $this->assert Equals(array(400, 600), $out);190 $this->assertSame(array(400, 600), $out); 188 191 189 192 $out = image_constrain_size_for_editor(64, 64, 'medium'); 190 $this->assert Equals(array(64, 64), $out);193 $this->assertSame(array(64, 64), $out); 191 194 192 195 // content_width should be ignored 193 196 $content_width = 350; 194 197 $out = image_constrain_size_for_editor(600, 400, 'medium'); 195 $this->assert Equals(array(500, 333), $out);198 $this->assertSame(array(500, 333), $out); 196 199 197 200 $content_width = $_content_width; 198 201 } … … 204 207 205 208 $content_width = 400; 206 209 $out = image_constrain_size_for_editor(600, 400, 'full'); 207 $this->assert Equals(array(600, 400), $out);210 $this->assertSame(array(600, 400), $out); 208 211 209 212 $out = image_constrain_size_for_editor(64, 64, 'full'); 210 $this->assert Equals(array(64, 64), $out);213 $this->assertSame(array(64, 64), $out); 211 214 212 215 // content_width default is 500 213 216 $content_width = 0; 214 217 215 218 $out = image_constrain_size_for_editor(600, 400, 'full'); 216 $this->assert Equals(array(600, 400), $out);219 $this->assertSame(array(600, 400), $out); 217 220 218 221 $out = image_constrain_size_for_editor(64, 64, 'full'); 219 $this->assert Equals(array(64, 64), $out);222 $this->assertSame(array(64, 64), $out); 220 223 221 224 $content_width = $_content_width; 222 225 } -
tests/phpunit/tests/image/editor_gd.php
282 282 283 283 // #0 284 284 array( 285 'file' => 'waffles-10x 6.jpg',285 'file' => 'waffles-10x7.jpg', 286 286 'width' => 10, 287 'height' => 6,287 'height' => 7, 288 288 'mime-type' => 'image/jpeg', 289 289 ), 290 290 … … 322 322 323 323 // #5 324 324 array( 325 'file' => 'waffles-55x3 6.jpg',325 'file' => 'waffles-55x37.jpg', 326 326 'width' => 55, 327 'height' => 3 6,327 'height' => 37, 328 328 'mime-type' => 'image/jpeg', 329 329 ), 330 330 331 331 // #6 332 332 array( 333 'file' => 'waffles-8 2x55.jpg',334 'width' => 8 2,333 'file' => 'waffles-83x55.jpg', 334 'width' => 83, 335 335 'height' => 55, 336 336 'mime-type' => 'image/jpeg', 337 337 ), -
tests/phpunit/tests/image/resize.php
25 25 function test_resize_png() { 26 26 $image = $this->resize_helper( DIR_TESTDATA.'/images/test-image.png', 25, 25 ); 27 27 28 if ( ! is_string( $image ) ) { // WP_Error, stop GLib-GObject-CRITICAL assertion 29 $this->markTestSkipped( sprintf( 'No PNG support in the editor engine %s on this system', $this->editor_engine ) ); 30 return; 31 } 32 28 33 $this->assertEquals( 'test-image-25x25.png', basename($image) ); 29 34 list($w, $h, $type) = getimagesize($image); 30 35 $this->assertEquals( 25, $w ); … … 37 42 function test_resize_gif() { 38 43 $image = $this->resize_helper( DIR_TESTDATA.'/images/test-image.gif', 25, 25 ); 39 44 45 if ( ! is_string( $image ) ) { // WP_Error, stop GLib-GObject-CRITICAL assertion 46 $this->markTestSkipped( sprintf( 'No GIF support in the editor engine %s on this system', $this->editor_engine ) ); 47 return; 48 } 49 40 50 $this->assertEquals( 'test-image-25x25.gif', basename($image) ); 41 51 list($w, $h, $type) = getimagesize($image); 42 52 $this->assertEquals( 25, $w ); … … 57 67 function test_resize_thumb_128x96() { 58 68 $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 128, 96 ); 59 69 60 $this->assertEquals( '2007-06-17DSC_4173-6 3x96.jpg', basename($image) );70 $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', basename($image) ); 61 71 list($w, $h, $type) = getimagesize($image); 62 $this->assertEquals( 6 3, $w );72 $this->assertEquals( 64, $w ); 63 73 $this->assertEquals( 96, $h ); 64 74 $this->assertEquals( IMAGETYPE_JPEG, $type ); 65 75 … … 69 79 function test_resize_thumb_128x0() { 70 80 $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 128, 0 ); 71 81 72 $this->assertEquals( '2007-06-17DSC_4173-128x19 2.jpg', basename($image) );82 $this->assertEquals( '2007-06-17DSC_4173-128x193.jpg', basename($image) ); 73 83 list($w, $h, $type) = getimagesize($image); 74 84 $this->assertEquals( 128, $w ); 75 $this->assertEquals( 19 2, $h );85 $this->assertEquals( 193, $h ); 76 86 $this->assertEquals( IMAGETYPE_JPEG, $type ); 77 87 78 88 unlink( $image ); … … 81 91 function test_resize_thumb_0x96() { 82 92 $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 0, 96 ); 83 93 84 $this->assertEquals( '2007-06-17DSC_4173-6 3x96.jpg', basename($image) );94 $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', basename($image) ); 85 95 list($w, $h, $type) = getimagesize($image); 86 $this->assertEquals( 6 3, $w );96 $this->assertEquals( 64, $w ); 87 97 $this->assertEquals( 96, $h ); 88 98 $this->assertEquals( IMAGETYPE_JPEG, $type ); 89 99 … … 142 152 * @ticket 6821 143 153 */ 144 154 public function test_resize_bad_image() { 155 156 if ( $this->editor_engine == 'WP_Image_Editor_Imagick' ) { 157 $this->markTestSkipped( sprintf( 'Avoid GLib-GObject-CRITICAL assertion in %s', $this->editor_engine ) ); 158 return; 159 } 160 145 161 $image = $this->resize_helper( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 ); 146 162 $this->assertInstanceOf( 'WP_Error', $image ); 147 163 $this->assertEquals( 'invalid_image', $image->get_error_code() ); -
src/wp-includes/media.php
377 377 $smaller_ratio = min( $width_ratio, $height_ratio ); 378 378 $larger_ratio = max( $width_ratio, $height_ratio ); 379 379 380 if ( intval( $current_width * $larger_ratio ) > $max_width || intval( $current_height * $larger_ratio ) > $max_height )380 if ( intval( round ( $current_width * $larger_ratio ) ) > $max_width || intval( round ( $current_height * $larger_ratio ) ) > $max_height ) { 381 381 // The larger ratio is too big. It would result in an overflow. 382 382 $ratio = $smaller_ratio; 383 else383 } else { 384 384 // The larger ratio fits, and is likely to be a more "snug" fit. 385 385 $ratio = $larger_ratio; 386 } 386 387 387 388 // Very small dimensions may result in 0, 1 should be the minimum. 388 $w = max ( 1, intval( $current_width * $ratio) );389 $h = max ( 1, intval( $current_height * $ratio) );389 $w = max ( 1, intval( round ( $current_width * $ratio ) ) ); 390 $h = max ( 1, intval( round ( $current_height * $ratio ) ) ); 390 391 392 // xxxNo test coverage for keeping or removing the following check. 393 // xxxIt predates https://core.trac.wordpress.org/ticket/18532 and is probably not needed. The result is now 118x177. 394 391 395 // Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short 392 396 // We also have issues with recursive calls resulting in an ever-changing result. Constraining to the result of a constraint should yield the original result. 393 397 // Thus we look for dimensions that are one pixel shy of the max value and bump them up 398 399 // Note $did_width means it is possible $smaller_ratio == $width_ratio. 394 400 if ( $did_width && $w == $max_width - 1 ) 395 401 $w = $max_width; // Round it up 402 403 // Note $did_height means it is possible $smaller_ratio == $height_ratio. 396 404 if ( $did_height && $h == $max_height - 1 ) 397 405 $h = $max_height; // Round it up 398 406 399 return a rray( $w, $h);407 return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height ); 400 408 } 401 409 402 410 /** … … 458 466 $new_h = min($dest_h, $orig_h); 459 467 460 468 if ( !$new_w ) { 461 $new_w = intval($new_h * $aspect_ratio); 469 // xxxNo test coverage for `intval( round( ) )` vs. `intval( )`. https://core.trac.wordpress.org/ticket/18532 470 // $new_w = intval( $new_h * $aspect_ratio ); // xxx 471 $new_w = intval( round( $new_h * $aspect_ratio ) ); 462 472 } 463 473 464 474 if ( !$new_h ) { 465 $new_h = intval($new_w / $aspect_ratio); 475 // xxxNo test coverage for `intval( round( ) )` vs. `intval( )`. https://core.trac.wordpress.org/ticket/18532 476 // $new_h = intval( $new_w / $aspect_ratio ); // xxx 477 $new_h = intval( round( $new_w / $aspect_ratio ) ); 466 478 } 467 479 468 480 $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);