_crop_image_resource()
Crops an image resource. Internal use only.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
resource|GdImage. (maybe) cropped image resource or GdImage instance.
Usage
_crop_image_resource( $img, $x, $y, $w, $h );
- $img(resource|GdImage) (required)
- Image resource or GdImage instance.
- $x(float) (required)
- Source point x-coordinate.
- $y(float) (required)
- Source point y-coordinate.
- $w(float) (required)
- Source width.
- $h(float) (required)
- Source height.
Changelog
| Since 2.9.0 | Introduced. |
_crop_image_resource() crop image resource code WP 7.0
function _crop_image_resource( $img, $x, $y, $w, $h ) {
$dst = wp_imagecreatetruecolor( $w, $h );
if ( is_gd_image( $dst ) ) {
if ( imagecopy( $dst, $img, 0, 0, $x, $y, $w, $h ) ) {
if ( PHP_VERSION_ID < 80000 ) { // imagedestroy() has no effect as of PHP 8.0.
imagedestroy( $img );
}
$img = $dst;
}
}
return $img;
}