Ticket #26823: 26823.diff
File 26823.diff, 19.1 KB (added by , 11 years ago) |
---|
-
src/wp-includes/class-wp-image-editor-gd.php
205 205 $orig_size = $this->size; 206 206 207 207 foreach ( $sizes as $size => $size_data ) { 208 if ( ! ( isset( $size_data['width'] ) && isset( $size_data['height'] )) )208 if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) 209 209 continue; 210 210 211 if ( ! isset( $size_data['crop'] ) ) 211 if ( ! isset( $size_data['width'] ) ) { 212 $size_data['width'] = 0; 213 } 214 215 if ( ! isset( $size_data['height'] ) ) { 216 $size_data['height'] = 0; 217 } 218 219 if ( ! isset( $size_data['crop'] ) ) { 212 220 $size_data['crop'] = false; 221 } 213 222 214 223 $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); 215 224 -
src/wp-includes/class-wp-image-editor-imagick.php
272 272 if ( ! $this->image ) 273 273 $this->image = $orig_image->getImage(); 274 274 275 if ( ! ( isset( $size_data['width'] ) && isset( $size_data['height'] )) )275 if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) 276 276 continue; 277 277 278 if ( ! isset( $size_data['width'] ) ) { 279 $size_data['width'] = 0; 280 } 281 282 if ( ! isset( $size_data['height'] ) ) { 283 $size_data['height'] = 0; 284 } 285 278 286 if ( ! isset( $size_data['crop'] ) ) 279 287 $size_data['crop'] = false; 280 288 -
tests/phpunit/tests/image/editor_gd.php
18 18 19 19 /** 20 20 * Check support for GD compatible mime types. 21 * 21 * 22 22 */ 23 23 public function test_supports_mime_type() { 24 24 $gd_image_editor = new WP_Image_Editor_GD( null ); … … 30 30 31 31 /** 32 32 * Test resizing an image, not using crop 33 *34 33 */ 35 34 public function test_resize() { 35 $file = DIR_TESTDATA . '/images/waffles.jpg'; 36 $gd_image_editor = new WP_Image_Editor_GD( $file ); 37 $gd_image_editor->load(); 38 $gd_image_editor->resize( 100, 50 ); 36 39 37 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 40 $this->assertEquals( array( 'width' => 75, 'height' => 50 ), $gd_image_editor->get_size() ); 41 } 38 42 43 /** 44 * Test resizing an multi resizong image, not using crop 45 */ 46 public function test_multi_resize() { 47 $file = DIR_TESTDATA . '/images/waffles.jpg'; 39 48 $gd_image_editor = new WP_Image_Editor_GD( $file ); 40 49 $gd_image_editor->load(); 41 50 42 $gd_image_editor->resize( 100, 50 ); 51 $sizes_array = array( array('width' => 50, 'height' => 50 ) ); 52 $resized = $gd_image_editor->multi_resize( $sizes_array ); 43 53 44 $this->assertEquals( array( 'width' => 50, 'height' => 50 ), $gd_image_editor->get_size() ); 54 $expected_array = array( array( 55 'file' => 'waffles-50x33.jpg', 56 'width' => 50, 57 'height' => 33, 58 'mime-type' => 'image/jpeg' 59 ) ); 60 61 $this->assertEquals( $expected_array, $resized ); 45 62 } 46 63 47 64 /** 65 * Test resizing an multi resizong image, and then load the image to check size 66 */ 67 public function test_multi_resize_check_is_resized() { 68 $file = DIR_TESTDATA . '/images/waffles.jpg'; 69 $gd_image_editor = new WP_Image_Editor_GD( $file ); 70 $gd_image_editor->load(); 71 72 $sizes_array = array( array('width' => 50, 'height' => 50 ) ); 73 $resized = $gd_image_editor->multi_resize( $sizes_array ); 74 75 $gd_image_output = new WP_Image_Editor_GD( DIR_TESTDATA . '/images/'. $resized[0]['file'] ); 76 $gd_image_output->load(); 77 78 $this->assertEquals( array( 'width' => 50, 'height' => 33 ), $gd_image_output->get_size() ); 79 } 80 81 /** 82 * Test resizing an multi resizong image array in array out 83 */ 84 public function test_multi_resize_array() { 85 $file = DIR_TESTDATA . '/images/waffles.jpg'; 86 $gd_image_editor = new WP_Image_Editor_GD( $file ); 87 $gd_image_editor->load(); 88 89 $sizes_array = array( 90 // #1 - resizes to 100x100 pixel, square-cropped image 91 array('width' => 10, 'height' => 10, 'crop' => false ), 92 // #2 - resizes to 200 pixel max width/height, non-cropped image 93 array('width' => 75, 'height' => 50, 'crop' => true ), 94 // #3 - resizes to 200 pixel max height, non-cropped image 95 array('width' => 9999, 'height' => 20, 'crop' => false ), 96 // #3 - resizes to 450 pixel max width, non-cropped image 97 array('width' => 45, 'height' => 9999, 'crop' => true ) 98 ); 99 100 $resized = $gd_image_editor->multi_resize( $sizes_array ); 101 102 $expected_array = array( 103 // #1 - resizes to 100x100 pixel, square-cropped image 104 array( 105 'file' => 'waffles-10x6.jpg', 106 'width' => 10, 107 'height' => 6 , 108 'mime-type' => 'image/jpeg' 109 ), 110 // #2 - resizes to 200 pixel max width/height, square-cropped image 111 array( 112 'file' => 'waffles-75x50.jpg', 113 'width' => 75, 114 'height' => 50, 115 'mime-type' => 'image/jpeg' 116 ), 117 // #3 - resizes to 200 pixel max height, non-cropped image 118 array( 119 'file' => 'waffles-30x20.jpg', 120 'width' => 30, 121 'height' => 20, 122 'mime-type' => 'image/jpeg' 123 ), 124 // #4 - resizes to 450 pixel max width, non-cropped image 125 array( 126 'file' => 'waffles-45x400.jpg', 127 'width' => 45, 128 'height' => 400, 129 'mime-type' => 'image/jpeg' 130 ) 131 ); 132 $this->assertEquals( $expected_array, $resized ); 133 } 134 135 /** 136 * Test resizing an image, no height 137 */ 138 public function test_multi_resize_mising_height() { 139 $file = DIR_TESTDATA . '/images/waffles.jpg'; 140 $gd_image_editor = new WP_Image_Editor_GD( $file ); 141 $gd_image_editor->load(); 142 $sizes_array = array( array( 'width' => 50 ) ); 143 $resized = $gd_image_editor->multi_resize( $sizes_array ); 144 145 $expected_array = array( array( 146 'file' => 'waffles-50x33.jpg', 147 'width' => 50, 148 'height' => 33, 149 'mime-type' => 'image/jpeg' 150 ) ); 151 $this->assertEquals( $expected_array, $resized ); 152 } 153 /** 154 * Test resizing an multi resize image, no width 155 */ 156 public function test_multi_resize_mising_width() { 157 $file = DIR_TESTDATA . '/images/waffles.jpg'; 158 $gd_image_editor = new WP_Image_Editor_GD( $file ); 159 $gd_image_editor->load(); 160 161 $sizes_array = array( array( 'height' => 50 ) ); 162 $resized = $gd_image_editor->multi_resize( $sizes_array ); 163 164 $expected_array = array( array( 165 'file' => 'waffles-75x50.jpg', 166 'width' => 75, 167 'height' => 50, 168 'mime-type' => 'image/jpeg' 169 ) ); 170 $this->assertEquals( $expected_array, $resized ); 171 } 172 173 /** 174 * Test resizing an multi resize image, null input 175 */ 176 public function test_multi_resize_width_set_to_null() { 177 $file = DIR_TESTDATA . '/images/waffles.jpg'; 178 $gd_image_editor = new WP_Image_Editor_GD( $file ); 179 $gd_image_editor->load(); 180 181 $sizes_array = array( array( 'height' => 50,'width' => null ) ); 182 $resized = $gd_image_editor->multi_resize( $sizes_array ); 183 184 $expected_array = array( array( 185 'file' => 'waffles-75x50.jpg', 186 'width' => 75, 187 'height' => 50, 188 'mime-type' => 'image/jpeg' 189 ) ); 190 $this->assertEquals( $expected_array, $resized ); 191 } 192 /** 193 * Test resizing an multi resize image, Null import 194 */ 195 public function test_multi_resize_height_set_to_null() { 196 $file = DIR_TESTDATA . '/images/waffles.jpg'; 197 $gd_image_editor = new WP_Image_Editor_GD( $file ); 198 $gd_image_editor->load(); 199 200 $sizes_array = array( array( 'height' => null,'width' => 50 ) ); 201 $resized = $gd_image_editor->multi_resize( $sizes_array ); 202 203 $expected_array = array( array( 204 'file' => 'waffles-50x33.jpg', 205 'width' => 50, 206 'height' => 33, 207 'mime-type' => 'image/jpeg' 208 ) ); 209 $this->assertEquals( $expected_array, $resized ); 210 } 211 212 /** 213 * Test resizing an multi resize image, missus value 214 */ 215 public function test_multi_resize_width_set_to_missus() { 216 $file = DIR_TESTDATA . '/images/waffles.jpg'; 217 $gd_image_editor = new WP_Image_Editor_GD( $file ); 218 $gd_image_editor->load(); 219 220 $sizes_array = array( array( 'height' => 50,'width' => -50 ) ); 221 $resized = $gd_image_editor->multi_resize( $sizes_array ); 222 223 $expected_array = array( array( 224 'file' => 'waffles-75x50.jpg', 225 'width' => 75, 226 'height' => 50, 227 'mime-type' => 'image/jpeg' 228 ) ); 229 $this->assertEquals( $expected_array, $resized ); 230 } 231 /** 232 * Test resizing an multi resize image, missus value 233 */ 234 public function test_multi_resize_height_set_to_missus() { 235 $file = DIR_TESTDATA . '/images/waffles.jpg'; 236 $gd_image_editor = new WP_Image_Editor_GD( $file ); 237 $gd_image_editor->load(); 238 239 $sizes_array = array( array( 'height' => -65119,'width' => 200 ) ); 240 $resized = $gd_image_editor->multi_resize( $sizes_array ); 241 242 $expected_array = array( array( 243 'file' => 'waffles-200x133.jpg', 244 'width' => 200, 245 'height' => 133, 246 'mime-type' => 'image/jpeg' 247 ) ); 248 $this->assertEquals( $expected_array, $resized ); 249 } 250 251 /** 48 252 * Test resizing an image including cropping 49 * 253 * 50 254 */ 51 255 public function test_resize_and_crop() { 52 53 256 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 54 55 257 $gd_image_editor = new WP_Image_Editor_GD( $file ); 56 258 $gd_image_editor->load(); 57 58 259 $gd_image_editor->resize( 100, 50, true ); 59 260 60 261 $this->assertEquals( array( 'width' => 100, 'height' => 50 ), $gd_image_editor->get_size() ); … … 64 265 * Test cropping an image 65 266 */ 66 267 public function test_crop() { 67 68 268 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 69 70 269 $gd_image_editor = new WP_Image_Editor_GD( $file ); 71 270 $gd_image_editor->load(); 72 73 271 $gd_image_editor->crop( 0, 0, 50, 50 ); 74 272 75 273 $this->assertEquals( array( 'width' => 50, 'height' => 50 ), $gd_image_editor->get_size() ); 76 77 274 } 78 275 79 276 /** … … 80 277 * Test rotating an image 180 deg 81 278 */ 82 279 public function test_rotate() { 83 84 280 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 85 86 281 $gd_image_editor = new WP_Image_Editor_GD( $file ); 87 282 $gd_image_editor->load(); 88 283 … … 100 295 * Test flipping an image 101 296 */ 102 297 public function test_flip() { 103 104 298 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 105 106 299 $gd_image_editor = new WP_Image_Editor_GD( $file ); 107 300 $gd_image_editor->load(); 108 301 … … 118 311 119 312 /** 120 313 * Test the image created with WP_Image_Edior_GD preserves alpha when resizing 121 * 314 * 122 315 * @ticket 23039 123 316 */ 124 317 public function test_image_preserves_alpha_on_resize() { 125 126 318 $file = DIR_TESTDATA . '/images/transparent.png'; 127 128 319 $editor = wp_get_image_editor( $file ); 129 320 $editor->load(); 130 321 $editor->resize(5,5); 322 131 323 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 132 133 324 $editor->save( $save_to_file ); 134 325 135 326 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 327 } 136 328 137 }138 139 329 /** 140 330 * Test the image created with WP_Image_Edior_GD preserves alpha with no resizing etc 141 * 331 * 142 332 * @ticket 23039 143 333 */ 144 334 public function test_image_preserves_alpha() { 145 146 335 $file = DIR_TESTDATA . '/images/transparent.png'; 147 148 336 $editor = wp_get_image_editor( $file ); 149 337 $editor->load(); 150 338 151 339 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 152 153 340 $editor->save( $save_to_file ); 154 341 155 342 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 156 343 } 157 158 } 344 } 345 No newline at end of file -
tests/phpunit/tests/image/editor_imagick.php
25 25 26 26 /** 27 27 * Check support for Image Magick compatible mime types. 28 * 28 * 29 29 */ 30 30 public function test_supports_mime_type() { 31 31 … … 38 38 39 39 /** 40 40 * Test resizing an image, not using crop 41 * 41 * 42 42 */ 43 43 public function test_resize() { 44 44 … … 51 51 52 52 $this->assertEquals( array( 'width' => 50, 'height' => 50 ), $imagick_image_editor->get_size() ); 53 53 } 54 /** 55 * Test resizing an multi resizong image, not using crop 56 */ 57 public function test_multi_resize() { 58 $file = DIR_TESTDATA . '/images/waffles.jpg'; 59 $gd_image_editor = new WP_Image_Editor_Imagick( $file ); 60 $gd_image_editor->load(); 54 61 62 $sizes_array = array( array( 'width' => 50, 'height' => 50 ) ); 63 $resized = $gd_image_editor->multi_resize( $sizes_array ); 64 65 $expected_array = array( array( 66 'file' => 'waffles-50x33.jpg', 67 'width' => 50, 68 'height' => 33, 69 'mime-type' => 'image/jpeg' 70 ) ); 71 $this->assertEquals( $expected_array, $resized ); 72 } 73 55 74 /** 75 * Test resizing an multi resizong image, and then load the image to check size 76 */ 77 public function test_multi_resize_check_is_resized() { 78 $file = DIR_TESTDATA . '/images/waffles.jpg'; 79 $gd_image_editor = new WP_Image_Editor_Imagick( $file ); 80 $gd_image_editor->load(); 81 82 $sizes_array = array( array('width' => 50, 'height' => 50 ) ); 83 $resized = $gd_image_editor->multi_resize( $sizes_array ); 84 85 $gd_image_output = new WP_Image_Editor_Imagick( DIR_TESTDATA . '/images/'. $resized[0]['file'] ); 86 $gd_image_output->load(); 87 $this->assertEquals( array( 'width' => 50, 'height' => 33 ), $gd_image_output->get_size() ); 88 } 89 90 /** 91 * Test resizing an multi resizong image array in array out 92 */ 93 public function test_multi_resize_array() { 94 $file = DIR_TESTDATA . '/images/waffles.jpg'; 95 $gd_image_editor = new WP_Image_Editor_Imagick( $file ); 96 $gd_image_editor->load(); 97 98 $sizes_array = array( 99 // #1 - resizes to 100x100 pixel, square-cropped image 100 array('width' => 10, 'height' => 10, 'crop' => false ), 101 // #2 - resizes to 200 pixel max width/height, non-cropped image 102 array('width' => 75, 'height' => 50, 'crop' => true ), 103 // #3 - resizes to 200 pixel max height, non-cropped image 104 array('width' => 9999, 'height' => 20, 'crop' => false ), 105 // #4 - resizes to 450 pixel max width, non-cropped image 106 array('width' => 45, 'height' => 9999, 'crop' => true ) 107 ); 108 109 $resized = $gd_image_editor->multi_resize( $sizes_array ); 110 111 $expected_array = array( 112 // #1 - resizes to 100x100 pixel, square-cropped image 113 array( 114 'file' => 'waffles-10x6.jpg', 115 'width' => 10, 116 'height' => 6 , 117 'mime-type' => 'image/jpeg' 118 ), 119 // #2 - resizes to 200 pixel max width/height, square-cropped image 120 array( 121 'file' => 'waffles-75x50.jpg', 122 'width' => 75, 123 'height' => 50, 124 'mime-type' => 'image/jpeg' 125 ), 126 // #3 - resizes to 200 pixel max height, non-cropped image 127 array( 128 'file' => 'waffles-30x20.jpg', 129 'width' => 30, 130 'height' => 20, 131 'mime-type' => 'image/jpeg' 132 ), 133 // #4 - resizes to 450 pixel max width, non-cropped image 134 array( 135 'file' => 'waffles-45x400.jpg', 136 'width' => 45, 137 'height' => 400, 138 'mime-type' => 'image/jpeg' 139 ) 140 ); 141 $this->assertEquals( $expected_array, $resized ); 142 } 143 144 /** 145 * Test resizing an image, no height 146 */ 147 public function test_multi_resize_mising_height() { 148 $file = DIR_TESTDATA . '/images/waffles.jpg'; 149 $gd_image_editor = new WP_Image_Editor_Imagick( $file ); 150 $gd_image_editor->load(); 151 152 $sizes_array = array( array( 'width' => 50 ) ); 153 $resized = $gd_image_editor->multi_resize( $sizes_array ); 154 155 $expected_array = array( array( 156 'file' => 'waffles-50x33.jpg', 157 'width' => 50, 158 'height' => 33, 159 'mime-type' => 'image/jpeg' 160 ) ); 161 $this->assertEquals( $expected_array, $resized ); 162 } 163 /** 164 * Test resizing an multi resize image, no width 165 */ 166 public function test_multi_resize_mising_width() { 167 $file = DIR_TESTDATA . '/images/waffles.jpg'; 168 $gd_image_editor = new WP_Image_Editor_Imagick( $file ); 169 $gd_image_editor->load(); 170 171 $sizes_array = array( array( 'height' => 50 ) ); 172 $resized = $gd_image_editor->multi_resize( $sizes_array ); 173 174 $expected_array = array( array( 175 'file' => 'waffles-75x50.jpg', 176 'width' => 75, 177 'height' => 50, 178 'mime-type' => 'image/jpeg' 179 ) ); 180 $this->assertEquals( $expected_array, $resized ); 181 } 182 183 /** 184 * Test resizing an multi resize image, null input 185 */ 186 public function test_multi_resize_width_set_to_null() { 187 $file = DIR_TESTDATA . '/images/waffles.jpg'; 188 $gd_image_editor = new WP_Image_Editor_Imagick( $file ); 189 $gd_image_editor->load(); 190 191 $sizes_array = array( array( 'height' => 50, 'width' => null ) ); 192 $resized = $gd_image_editor->multi_resize( $sizes_array ); 193 194 $expected_array = array( array( 195 'file' => 'waffles-75x50.jpg', 196 'width' => 75, 197 'height' => 50, 198 'mime-type' => 'image/jpeg' 199 ) ); 200 $this->assertEquals( $expected_array, $resized ); 201 } 202 /** 203 * Test resizing an multi resize image, Null import 204 */ 205 public function test_multi_resize_height_set_to_null() { 206 $file = DIR_TESTDATA . '/images/waffles.jpg'; 207 $gd_image_editor = new WP_Image_Editor_Imagick( $file ); 208 $gd_image_editor->load(); 209 210 $sizes_array = array( array( 'height' => null, 'width' => 50 ) ); 211 $resized = $gd_image_editor->multi_resize( $sizes_array ); 212 213 $expected_array = array( array( 214 'file' => 'waffles-50x33.jpg', 215 'width' => 50, 216 'height' => 33, 217 'mime-type' => 'image/jpeg' 218 ) ); 219 $this->assertEquals( $expected_array, $resized ); 220 } 221 222 /** 223 * Test resizing an multi resize image, missus value 224 * 225 */ 226 public function test_multi_resize_width_set_to_missus() { 227 $file = DIR_TESTDATA . '/images/waffles.jpg'; 228 $gd_image_editor = new WP_Image_Editor_Imagick( $file ); 229 $gd_image_editor->load(); 230 231 $sizes_array = array( array( 'height' => 50, 'width' => -50 ) ); 232 $resized = $gd_image_editor->multi_resize( $sizes_array ); 233 234 $expected_array = array( array( 235 'file' => 'waffles-75x50.jpg', 236 'width' => 75, 237 'height' => 50, 238 'mime-type' => 'image/jpeg' 239 ) ); 240 241 $this->assertEquals( $expected_array, $resized ); 242 } 243 /** 244 * Test resizing an multi resize image, missus value 245 */ 246 public function test_multi_resize_height_set_to_missus() { 247 $file = DIR_TESTDATA . '/images/waffles.jpg'; 248 $gd_image_editor = new WP_Image_Editor_Imagick( $file ); 249 $gd_image_editor->load(); 250 251 $sizes_array = array( array( 'height' => -65119, 'width' => 200 ) ); 252 $resized = $gd_image_editor->multi_resize( $sizes_array ); 253 254 $expected_array = array( array( 255 'file' => 'waffles-200x133.jpg', 256 'width' => 200, 257 'height' => 133, 258 'mime-type' => 'image/jpeg' 259 ) ); 260 $this->assertEquals( $expected_array, $resized ); 261 } 262 263 /** 56 264 * Test resizing an image including cropping 57 * 265 * 58 266 */ 59 267 public function test_resize_and_crop() { 60 268 … … 137 345 $editor->load(); 138 346 $editor->resize(5,5); 139 347 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 140 348 141 349 $editor->save( $save_to_file ); 142 350 143 351 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); 144 352 145 353 } 146 354 147 355 /** 148 356 * Test the image created with WP_Image_Edior_Imagick preserves alpha with no resizing etc 149 357 * … … 157 365 $editor->load(); 158 366 159 367 $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; 160 368 161 369 $editor->save( $save_to_file ); 162 370 163 371 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );