_crop_image_resource

Crops an image resource.

Description

(resource) _crop_image_resource( (resource) $img, (float) $x, (float) $y, (float) $w, (float) $h ); 

Internal use only.

Returns (resource)

(maybe) cropped image resource.

Parameters (5)

0. $img (resource)
Image resource.
1. $x (float)
Source point x-coordinate.
2. $y (float)
Source point y-cooredinate.
3. $w (float)
Source width.
4. $h (float)
Source height.

Usage

  1. if ( !function_exists( '_crop_image_resource' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/image-edit.php'; 
  3.  
  4. // Image resource. 
  5. $img = null; 
  6.  
  7. // Source point x-coordinate. 
  8. $x = null; 
  9.  
  10. // Source point y-cooredinate. 
  11. $y = null; 
  12.  
  13. // Source width. 
  14. $w = null; 
  15.  
  16. // Source height. 
  17. $h = null; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = _crop_image_resource($img, $x, $y, $w, $h); 
  21.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/image-edit.php  
  1. function _crop_image_resource($img, $x, $y, $w, $h) { 
  2. $dst = wp_imagecreatetruecolor($w, $h); 
  3. if ( is_resource($dst) ) { 
  4. if ( imagecopy($dst, $img, 0, 0, $x, $y, $w, $h) ) { 
  5. imagedestroy($img); 
  6. $img = $dst; 
  7. return $img;