Changeset 48798
- Timestamp:
- 08/16/2020 01:31:57 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/image-edit.php
r48375 r48798 292 292 * @deprecated 3.5.0 Use {@see 'image_editor_save_pre'} instead. 293 293 * 294 * @param resource $image Image resource to be streamed.295 * @param int $attachment_id The attachment post ID.294 * @param resource|GdImage $image Image resource to be streamed. 295 * @param int $attachment_id The attachment post ID. 296 296 */ 297 297 $image = apply_filters_deprecated( 'image_save_pre', array( $image, $attachment_id ), '3.5.0', 'image_editor_save_pre' ); … … 421 421 * 422 422 * @ignore 423 * @param resource $img Image resource.424 * @param float|int $angle Image rotation angle, in degrees.425 * @return resource| false GD image resource, false otherwise.423 * @param resource|GdImage $img Image resource. 424 * @param float|int $angle Image rotation angle, in degrees. 425 * @return resource|GdImage|false GD image resource or GdImage instance, false otherwise. 426 426 */ 427 427 function _rotate_image_resource( $img, $angle ) { 428 428 _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::rotate()' ); 429 429 430 if ( function_exists( 'imagerotate' ) ) { 430 431 $rotated = imagerotate( $img, $angle, 0 ); 431 if ( is_resource( $rotated ) ) { 432 433 if ( is_gd_image( $rotated ) ) { 432 434 imagedestroy( $img ); 433 435 $img = $rotated; 434 436 } 435 437 } 438 436 439 return $img; 437 440 } … … 445 448 * 446 449 * @ignore 447 * @param resource $img Image resource.448 * @param bool $horz Whether to flip horizontally.449 * @param bool $vert Whether to flip vertically.450 * @return resource (maybe) flipped image resource.450 * @param resource|GdImage $img Image resource or GdImage instance. 451 * @param bool $horz Whether to flip horizontally. 452 * @param bool $vert Whether to flip vertically. 453 * @return resource|GdImage (maybe) flipped image resource or GdImage instance. 451 454 */ 452 455 function _flip_image_resource( $img, $horz, $vert ) { 453 456 _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::flip()' ); 457 454 458 $w = imagesx( $img ); 455 459 $h = imagesy( $img ); 456 460 $dst = wp_imagecreatetruecolor( $w, $h ); 457 if ( is_resource( $dst ) ) { 461 462 if ( is_gd_image( $dst ) ) { 458 463 $sx = $vert ? ( $w - 1 ) : 0; 459 464 $sy = $horz ? ( $h - 1 ) : 0; … … 466 471 } 467 472 } 473 468 474 return $img; 469 475 } … … 475 481 * 476 482 * @ignore 477 * @param resource $img Image resource.478 * @param float $x Source point x-coordinate.479 * @param float $y Source point y-coordinate.480 * @param float $w Source width.481 * @param float $h Source height.482 * @return resource (maybe) cropped image resource.483 * @param resource|GdImage $img Image resource or GdImage instance. 484 * @param float $x Source point x-coordinate. 485 * @param float $y Source point y-coordinate. 486 * @param float $w Source width. 487 * @param float $h Source height. 488 * @return resource|GdImage (maybe) cropped image resource or GdImage instance. 483 489 */ 484 490 function _crop_image_resource( $img, $x, $y, $w, $h ) { 485 491 $dst = wp_imagecreatetruecolor( $w, $h ); 486 if ( is_resource( $dst ) ) { 492 493 if ( is_gd_image( $dst ) ) { 487 494 if ( imagecopy( $dst, $img, 0, 0, $x, $y, $w, $h ) ) { 488 495 imagedestroy( $img ); … … 490 497 } 491 498 } 499 492 500 return $img; 493 501 } … … 503 511 */ 504 512 function image_edit_apply_changes( $image, $changes ) { 505 if ( is_ resource( $image ) ) {513 if ( is_gd_image( $image ) ) { 506 514 /* translators: 1: $image, 2: WP_Image_Editor */ 507 515 _deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$image', 'WP_Image_Editor' ) ); … … 567 575 */ 568 576 $image = apply_filters( 'wp_image_editor_before_change', $image, $changes ); 569 } elseif ( is_ resource( $image ) ) {577 } elseif ( is_gd_image( $image ) ) { 570 578 571 579 /** … … 575 583 * @deprecated 3.5.0 Use {@see 'wp_image_editor_before_change'} instead. 576 584 * 577 * @param resource $image GD image resource.578 * @param array $changes Array of change operations.585 * @param resource|GdImage $image GD image resource or GdImage instance. 586 * @param array $changes Array of change operations. 579 587 */ 580 588 $image = apply_filters_deprecated( 'image_edit_before_change', array( $image, $changes ), '3.5.0', 'wp_image_editor_before_change' ); -
trunk/src/wp-admin/includes/image.php
r48586 r48798 914 914 915 915 /** 916 * Determines whether the value is an acceptable type for GD image functions. 917 * 918 * In PHP 8.0, the GD extension uses GdImage objects for its data structures. 919 * This function checks if the passed value is either a resource of type `gd` 920 * or a GdImage object instance. Any other type will return false. 921 * 922 * @since 5.6.0 923 * 924 * @param resource|GdImage|false $image A value to check for the type for. 925 * @return bool True if $image is either a GD image resource or GdImage instance, 926 * false otherwise. 927 */ 928 function is_gd_image( $image ) { 929 if ( is_resource( $image ) && 'gd' === get_resource_type( $image ) 930 || is_object( $image ) && $image instanceof GdImage 931 ) { 932 return true; 933 } 934 935 return false; 936 } 937 938 /** 916 939 * Load an image resource for editing. 917 940 * … … 919 942 * 920 943 * @param string $attachment_id Attachment ID. 921 * @param string $mime_type Image mime type. 922 * @param string $size Optional. Image size, defaults to 'full'. 923 * @return resource|false The resulting image resource on success, false on failure. 944 * @param string $mime_type Image mime type. 945 * @param string $size Optional. Image size. Default 'full'. 946 * @return resource|GdImage|false The resulting image resource or GdImage instance on success, 947 * false on failure. 924 948 */ 925 949 function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) { … … 943 967 break; 944 968 } 945 if ( is_resource( $image ) ) { 969 970 if ( is_gd_image( $image ) ) { 946 971 /** 947 972 * Filters the current image being loaded for editing. … … 949 974 * @since 2.9.0 950 975 * 951 * @param resource $image Current image.952 * @param string $attachment_id Attachment ID.953 * @param string $size Image size.976 * @param resource|GdImage $image Current image. 977 * @param string $attachment_id Attachment ID. 978 * @param string $size Image size. 954 979 */ 955 980 $image = apply_filters( 'load_image_to_edit', $image, $attachment_id, $size ); 981 956 982 if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { 957 983 imagealphablending( $image, false ); … … 959 985 } 960 986 } 987 961 988 return $image; 962 989 } … … 972 999 * 973 1000 * @param string $attachment_id Attachment ID. 974 * @param string $size Optional. Image size, defaults to'full'.1001 * @param string $size Optional. Image size. Default 'full'. 975 1002 * @return string|false File path or url on success, false on failure. 976 1003 */ -
trunk/src/wp-includes/class-wp-image-editor-gd.php
r48586 r48798 18 18 * GD Resource. 19 19 * 20 * @var resource 20 * @var resource|GdImage 21 21 */ 22 22 protected $image; … … 96 96 $this->image = @imagecreatefromstring( file_get_contents( $this->file ) ); 97 97 98 if ( ! is_ resource( $this->image ) ) {98 if ( ! is_gd_image( $this->image ) ) { 99 99 return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file ); 100 100 } … … 139 139 /** 140 140 * Resizes current image. 141 * Wraps _resize, since _resize returns a GD Resource.142 * 143 * At minimum, either a height or width must be provided.144 * If one of the two is set to null, the resize will145 * maintain aspect ratio according to the provided dimension.141 * 142 * Wraps `::_resize()` which returns a GD resource or GdImage instance. 143 * 144 * At minimum, either a height or width must be provided. If one of the two is set 145 * to null, the resize will maintain aspect ratio according to the provided dimension. 146 146 * 147 147 * @since 3.5.0 … … 159 159 $resized = $this->_resize( $max_w, $max_h, $crop ); 160 160 161 if ( is_ resource( $resized ) ) {161 if ( is_gd_image( $resized ) ) { 162 162 imagedestroy( $this->image ); 163 163 $this->image = $resized; … … 175 175 * @param int $max_h 176 176 * @param bool|array $crop 177 * @return resource| WP_Error177 * @return resource|GdImage|WP_Error 178 178 */ 179 179 protected function _resize( $max_w, $max_h, $crop = false ) { … … 189 189 imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); 190 190 191 if ( is_ resource( $resized ) ) {191 if ( is_gd_image( $resized ) ) { 192 192 $this->update_size( $dst_w, $dst_h ); 193 193 return $resized; … … 330 330 imagecopyresampled( $dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); 331 331 332 if ( is_ resource( $dst ) ) {332 if ( is_gd_image( $dst ) ) { 333 333 imagedestroy( $this->image ); 334 334 $this->image = $dst; … … 354 354 $rotated = imagerotate( $this->image, $angle, $transparency ); 355 355 356 if ( is_ resource( $rotated ) ) {356 if ( is_gd_image( $rotated ) ) { 357 357 imagealphablending( $rotated, true ); 358 358 imagesavealpha( $rotated, true ); … … 363 363 } 364 364 } 365 365 366 return new WP_Error( 'image_rotate_error', __( 'Image rotate failed.' ), $this->file ); 366 367 } … … 380 381 $dst = wp_imagecreatetruecolor( $w, $h ); 381 382 382 if ( is_ resource( $dst ) ) {383 if ( is_gd_image( $dst ) ) { 383 384 $sx = $vert ? ( $w - 1 ) : 0; 384 385 $sy = $horz ? ( $h - 1 ) : 0; … … 392 393 } 393 394 } 395 394 396 return new WP_Error( 'image_flip_error', __( 'Image flip failed.' ), $this->file ); 395 397 } … … 416 418 417 419 /** 418 * @param resource 419 * @param string|null $filename420 * @param string|null $mime_type420 * @param resource|GdImage $image 421 * @param string|null $filename 422 * @param string|null $mime_type 421 423 * @return array|WP_Error 422 424 */ -
trunk/src/wp-includes/class-wp-image-editor-imagick.php
r48586 r48798 549 549 return new WP_Error( 'image_crop_error', $e->getMessage() ); 550 550 } 551 551 552 return $this->update_size(); 552 553 } … … 583 584 return new WP_Error( 'image_rotate_error', $e->getMessage() ); 584 585 } 586 585 587 return true; 586 588 } -
trunk/src/wp-includes/deprecated.php
r48695 r48798 3197 3197 * 3198 3198 * @param string $file Filename of the image to load. 3199 * @return resource The resulting image resource on success, Error string on failure. 3199 * @return resource|GdImage|string The resulting image resource or GdImage instance on success, 3200 * error string on failure. 3200 3201 */ 3201 3202 function wp_load_image( $file ) { … … 3218 3219 $image = imagecreatefromstring( file_get_contents( $file ) ); 3219 3220 3220 if ( ! is_ resource( $image ) ) {3221 if ( ! is_gd_image( $image ) ) { 3221 3222 /* translators: %s: File name. */ 3222 3223 return sprintf( __( 'File “%s” is not an image.' ), $file ); -
trunk/src/wp-includes/media.php
r48782 r48798 3460 3460 * 3461 3461 * @param int $width Image width in pixels. 3462 * @param int $height Image height in pixels. .3463 * @return resource The GD image resource.3462 * @param int $height Image height in pixels. 3463 * @return resource|GdImage The GD image resource or GdImage instance. 3464 3464 */ 3465 3465 function wp_imagecreatetruecolor( $width, $height ) { 3466 3466 $img = imagecreatetruecolor( $width, $height ); 3467 if ( is_resource( $img ) && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { 3467 3468 if ( is_gd_image( $img ) 3469 && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) 3470 ) { 3468 3471 imagealphablending( $img, false ); 3469 3472 imagesavealpha( $img, true ); 3470 3473 } 3474 3471 3475 return $img; 3472 3476 } -
trunk/tests/phpunit/tests/image/functions.php
r48464 r48798 124 124 } 125 125 126 127 /** 128 * @ticket 50833 129 */ 130 function test_is_gd_image_invalid_types() { 131 $this->assertFalse( is_gd_image( new stdClass() ) ); 132 $this->assertFalse( is_gd_image( array() ) ); 133 $this->assertFalse( is_gd_image( null ) ); 134 135 $handle = fopen( __FILE__, 'r' ); 136 $this->assertFalse( is_gd_image( $handle ) ); 137 fclose( $handle ); 138 } 139 140 /** 141 * @ticket 50833 142 * @requires extension gd 143 */ 144 function test_is_gd_image_valid_types() { 145 $this->assertTrue( is_gd_image( imagecreate( 5, 5 ) ) ); 146 } 147 126 148 /** 127 149 * Test save image file and mime_types
Note: See TracChangeset
for help on using the changeset viewer.