WordPress at Your Fingertips
function is not described

_crop_image_resource() WP 2.9.0

Crops an image resource. Internal use only.

This is an internal function for using it by WP core itself. It's not recommended to use this function in your code.

No Hooks.


resource|GdImage. (maybe) cropped image resource or GdImage instance.


_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.


Since 2.9.0 Introduced.

Code of _crop_image_resource() WP 5.8.2

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 ) ) {
			imagedestroy( $img );
			$img = $dst;

	return $img;