load_image_to_edit

Load an image resource for editing.

Description

(resource|false) load_image_to_edit( (string) $attachment_id, (string) $mime_type, (string) $size = 'full' ); 

Returns (resource|false)

The resulting image resource on success, false on failure.

Parameters (3)

0. $attachment_id (string)
The attachment id.
1. $mime_type (string)
Image mime type.
2. $size — Optional. (string) => 'full'
Image size, defaults to full..

Usage

  1. if ( !function_exists( 'load_image_to_edit' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/image.php'; 
  3.  
  4. // The attachment id. 
  5. $attachment_id = ''; 
  6.  
  7. // Image mime type. 
  8. $mime_type = ''; 
  9.  
  10. // Optional. Image size, defaults to 'full'. 
  11. $size = 'full'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = load_image_to_edit($attachment_id, $mime_type, $size); 
  15.  

Defined (1)

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

/wp-admin/includes/image.php  
  1. function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) { 
  2. $filepath = _load_image_to_edit_path( $attachment_id, $size ); 
  3. if ( empty( $filepath ) ) 
  4. return false; 
  5.  
  6. switch ( $mime_type ) { 
  7. case 'image/jpeg': 
  8. $image = imagecreatefromjpeg($filepath); 
  9. break; 
  10. case 'image/png': 
  11. $image = imagecreatefrompng($filepath); 
  12. break; 
  13. case 'image/gif': 
  14. $image = imagecreatefromgif($filepath); 
  15. break; 
  16. default: 
  17. $image = false; 
  18. break; 
  19. if ( is_resource($image) ) { 
  20. /** 
  21. * Filters the current image being loaded for editing. 
  22. * @since 2.9.0 
  23. * @param resource $image Current image. 
  24. * @param string $attachment_id Attachment ID. 
  25. * @param string $size Image size. 
  26. */ 
  27. $image = apply_filters( 'load_image_to_edit', $image, $attachment_id, $size ); 
  28. if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) { 
  29. imagealphablending($image, false); 
  30. imagesavealpha($image, true); 
  31. return $image;