Title: load_image_to_edit
Published: April 25, 2014
Last modified: February 24, 2026

---

# load_image_to_edit( int $attachment_id, string $mime_type, string|int[] $size ): resource|GdImage|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#wp--skip-link--target)

Loads an image resource for editing.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#parameters)󠁿

 `$attachment_id`intrequired

Attachment ID.

`$mime_type`stringrequired

Image mime type.

`$size`string|int[]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](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#return)󠁿

 resource|GdImage|false The resulting image resource or GdImage instance on success,
false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#source)󠁿

    ```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;
    		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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/image.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/image.php#L1133)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/image.php#L1133-L1180)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#hooks)󠁿

 [apply_filters( ‘load_image_to_edit’, resource|GdImage $image, int $attachment_id, string|int[] $size )](https://developer.wordpress.org/reference/hooks/load_image_to_edit/)

Filters the current image being loaded for editing.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#related)󠁿

| Uses | Description | 
| [is_gd_image()](https://developer.wordpress.org/reference/functions/is_gd_image/)`wp-includes/media.php` |

Determines whether the value is an acceptable type for GD image functions.

  | 
| [_load_image_to_edit_path()](https://developer.wordpress.org/reference/functions/_load_image_to_edit_path/)`wp-admin/includes/image.php` |

Retrieves the path or URL of an attachment’s attached file.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/load_image_to_edit/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fload_image_to_edit%2F)
before being able to contribute a note or feedback.