Changeset 49751
- Timestamp:
- 12/04/2020 09:39:30 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-image-editor-gd.php
r49019 r49751 324 324 } 325 325 326 $dst = wp_imagecreatetruecolor( $dst_w, $dst_h ); 326 foreach ( array( $src_w, $src_h, $dst_w, $dst_h ) as $value ) { 327 if ( ! is_numeric( $value ) || (int) $value <= 0 ) { 328 return new WP_Error( 'image_crop_error', __( 'Image crop failed.' ), $this->file ); 329 } 330 } 331 332 $dst = wp_imagecreatetruecolor( (int) $dst_w, (int) $dst_h ); 327 333 328 334 if ( $src_abs ) { … … 335 341 } 336 342 337 imagecopyresampled( $dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w,$src_h );343 imagecopyresampled( $dst, $this->image, 0, 0, (int) $src_x, (int) $src_y, (int) $dst_w, (int) $dst_h, (int) $src_w, (int) $src_h ); 338 344 339 345 if ( is_gd_image( $dst ) ) { -
trunk/src/wp-includes/media.php
r49613 r49751 3506 3506 * @param int $width Image width in pixels. 3507 3507 * @param int $height Image height in pixels. 3508 * @return resource|GdImage The GD image resource or GdImage instance.3508 * @return resource|GdImage|false The GD image resource or GdImage instance on success. False on failure. 3509 3509 */ 3510 3510 function wp_imagecreatetruecolor( $width, $height ) { -
trunk/tests/phpunit/tests/image/editorGd.php
r49488 r49751 406 406 407 407 /** 408 * Test cropping an image 409 */ 410 public function test_crop() { 408 * Test cropping an image. 409 * 410 * @ticket 51937 411 * 412 * @dataProvider data_crop 413 */ 414 public function test_crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { 411 415 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 412 416 … … 414 418 $gd_image_editor->load(); 415 419 416 $gd_image_editor->crop( 0, 0, 50, 50);420 $gd_image_editor->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs ); 417 421 418 422 $this->assertSame( 419 423 array( 420 'width' => 50,421 'height' => 50,424 'width' => (int) $src_w, 425 'height' => (int) $src_h, 422 426 ), 423 427 $gd_image_editor->get_size() 428 ); 429 } 430 431 public function data_crop() { 432 return array( 433 'src height and width must be greater than 0' => array( 434 'src_x' => 0, 435 'src_y' => 0, 436 'src_w' => 50, 437 'src_h' => 50, 438 ), 439 'src height and width can be string but must be greater than 0' => array( 440 'src_x' => 10, 441 'src_y' => '10', 442 'src_w' => '50', 443 'src_h' => '50', 444 ), 445 'dst height and width must be greater than 0' => array( 446 'src_x' => 10, 447 'src_y' => '10', 448 'src_w' => 150, 449 'src_h' => 150, 450 'dst_w' => 150, 451 'dst_h' => 150, 452 ), 453 'dst height and width can be string but must be greater than 0' => array( 454 'src_x' => 10, 455 'src_y' => '10', 456 'src_w' => 150, 457 'src_h' => 150, 458 'dst_w' => '150', 459 'dst_h' => '150', 460 ), 461 ); 462 } 463 464 /** 465 * Test should return WP_Error when dimensions are not integer or are <= 0. 466 * 467 * @ticket 51937 468 * 469 * @dataProvider data_crop_invalid_dimensions 470 */ 471 public function test_crop_invalid_dimensions( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { 472 $file = DIR_TESTDATA . '/images/gradient-square.jpg'; 473 474 $gd_image_editor = new WP_Image_Editor_GD( $file ); 475 $gd_image_editor->load(); 476 477 $actual = $gd_image_editor->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs ); 478 479 $this->assertInstanceOf( 'WP_Error', $actual ); 480 $this->assertSame( 'image_crop_error', $actual->get_error_code() ); 481 } 482 483 public function data_crop_invalid_dimensions() { 484 return array( 485 'src height must be greater than 0' => array( 486 'src_x' => 0, 487 'src_y' => 0, 488 'src_w' => 100, 489 'src_h' => 0, 490 ), 491 'src width must be greater than 0' => array( 492 'src_x' => 10, 493 'src_y' => '10', 494 'src_w' => 0, 495 'src_h' => 100, 496 ), 497 'src height must be numeric and greater than 0' => array( 498 'src_x' => 10, 499 'src_y' => '10', 500 'src_w' => 100, 501 'src_h' => 'NaN', 502 ), 503 'dst height must be numeric and greater than 0' => array( 504 'src_x' => 0, 505 'src_y' => 0, 506 'src_w' => 100, 507 'src_h' => 50, 508 'dst_w' => '100', 509 'dst_h' => 'NaN', 510 ), 511 'src and dst height and width must be greater than 0' => array( 512 'src_x' => 0, 513 'src_y' => 0, 514 'src_w' => 0, 515 'src_h' => 0, 516 'dst_w' => 0, 517 'dst_h' => 0, 518 ), 519 'src and dst height and width can be string but must be greater than 0' => array( 520 'src_x' => 0, 521 'src_y' => 0, 522 'src_w' => '0', 523 'src_h' => '0', 524 'dst_w' => '0', 525 'dst_h' => '0', 526 ), 424 527 ); 425 528 }
Note: See TracChangeset
for help on using the changeset viewer.