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
if ( !function_exists( 'load_image_to_edit' ) ) { require_once ABSPATH . '/wp-admin/includes/image.php'; } // The attachment id. $attachment_id = ''; // Image mime type. $mime_type = ''; // Optional. Image size, defaults to 'full'. $size = 'full'; // NOTICE! Understand what this does before running. $result = load_image_to_edit($attachment_id, $mime_type, $size);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/image.php
- function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) {
- $filepath = _load_image_to_edit_path( $attachment_id, $size );
- if ( empty( $filepath ) )
- return false;
- switch ( $mime_type ) {
- case 'image/jpeg':
- $image = imagecreatefromjpeg($filepath);
- break;
- case 'image/png':
- $image = imagecreatefrompng($filepath);
- break;
- case 'image/gif':
- $image = imagecreatefromgif($filepath);
- break;
- default:
- $image = false;
- break;
- }
- if ( is_resource($image) ) {
- /**
- * Filters the current image being loaded for editing.
- *
- * @since 2.9.0
- *
- * @param resource $image Current image.
- * @param string $attachment_id Attachment ID.
- * @param string $size Image size.
- */
- $image = apply_filters( 'load_image_to_edit', $image, $attachment_id, $size );
- if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) {
- imagealphablending($image, false);
- imagesavealpha($image, true);
- }
- }
- return $image;
- }