load_image_to_edit

The timeline below displays how wordpress function load_image_to_edit has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Loads an image resource for editing.
 *
 * @since 2.9.0
 *
 * @param int          $attachment_id Attachment ID.
 * @param string       $mime_type     Image mime type.
 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array
 *                                    of width and height values in pixels (in that order). Default 'full'.
 * @return resource|GdImage|false The resulting image resource or GdImage instance on success,
 *                                false on failure.
 */
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;
        case 'image/webp':
            $image = false;
            if (function_exists('imagecreatefromwebp')) {
                $image = imagecreatefromwebp($filepath);
            }
            break;
        default:
            $image = false;
            break;
    }
    if (is_gd_image($image)) {
        /**
         * Filters the current image being loaded for editing.
         *
         * @since 2.9.0
         *
         * @param resource|GdImage $image         Current image.
         * @param int              $attachment_id Attachment ID.
         * @param string|int[]     $size          Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        $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;
}

WordPress Version: 5.8

/**
 * Load an image resource for editing.
 *
 * @since 2.9.0
 *
 * @param int          $attachment_id Attachment ID.
 * @param string       $mime_type     Image mime type.
 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array
 *                                    of width and height values in pixels (in that order). Default 'full'.
 * @return resource|GdImage|false The resulting image resource or GdImage instance on success,
 *                                false on failure.
 */
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;
        case 'image/webp':
            $image = false;
            if (function_exists('imagecreatefromwebp')) {
                $image = imagecreatefromwebp($filepath);
            }
            break;
        default:
            $image = false;
            break;
    }
    if (is_gd_image($image)) {
        /**
         * Filters the current image being loaded for editing.
         *
         * @since 2.9.0
         *
         * @param resource|GdImage $image         Current image.
         * @param int              $attachment_id Attachment ID.
         * @param string|int[]     $size          Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        $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;
}

WordPress Version: 5.6

/**
 * Load an image resource for editing.
 *
 * @since 2.9.0
 *
 * @param int          $attachment_id Attachment ID.
 * @param string       $mime_type     Image mime type.
 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array
 *                                    of width and height values in pixels (in that order). Default 'full'.
 * @return resource|GdImage|false The resulting image resource or GdImage instance on success,
 *                                false on failure.
 */
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_gd_image($image)) {
        /**
         * Filters the current image being loaded for editing.
         *
         * @since 2.9.0
         *
         * @param resource|GdImage $image         Current image.
         * @param int              $attachment_id Attachment ID.
         * @param string|int[]     $size          Requested image size. Can be any registered image size name, or
         *                                        an array of width and height values in pixels (in that order).
         */
        $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;
}

WordPress Version: 4.6

/**
 * Load an image resource for editing.
 *
 * @since 2.9.0
 *
 * @param string $attachment_id Attachment ID.
 * @param string $mime_type Image mime type.
 * @param string $size Optional. Image size, defaults to 'full'.
 * @return resource|false The resulting image resource on success, false on failure.
 */
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;
}

WordPress Version: 3.9

/**
 * Load an image resource for editing.
 *
 * @since 2.9.0
 *
 * @param string $attachment_id Attachment ID.
 * @param string $mime_type Image mime type.
 * @param string $size Optional. Image size, defaults to 'full'.
 * @return resource|false The resulting image resource on success, false on failure.
 */
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)) {
        /**
         * Filter 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;
}

WordPress Version: 3.7

/**
 * Load an image resource for editing.
 *
 * @since 2.9.0
 *
 * @param string $attachment_id Attachment ID.
 * @param string $mime_type Image mime type.
 * @param string $size Optional. Image size, defaults to 'full'.
 * @return resource|false The resulting image resource on success, false on failure.
 */
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)) {
        $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;
}