Title: wp_get_image_editor
Published: April 25, 2014
Last modified: August 20, 2026

---

# wp_get_image_editor( string $path, array $args = array() ): 󠀁[WP_Image_Editor](https://developer.wordpress.org/reference/classes/wp_image_editor/)󠁿|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_get_image_editor/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_get_image_editor/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_get_image_editor/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_get_image_editor/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_get_image_editor/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_get_image_editor/?output_format=md#user-contributed-notes)

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

Returns a [WP_Image_Editor](https://developer.wordpress.org/reference/classes/wp_image_editor/)
instance and loads file into it.

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

 `$path`stringrequired

Path to the file to load.

`$args`arrayoptional

Additional arguments for retrieving the image editor.

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_get_image_editor/?output_format=md#return)󠁿

 [WP_Image_Editor](https://developer.wordpress.org/reference/classes/wp_image_editor/)
|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) The [WP_Image_Editor](https://developer.wordpress.org/reference/classes/wp_image_editor/)
object on success, a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
object otherwise.

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

    ```php
    function wp_get_image_editor( $path, $args = array() ) {
    	$args['path'] = $path;

    	// If the mime type is not set in args, try to extract and set it from the file.
    	if ( ! isset( $args['mime_type'] ) ) {
    		$file_info = wp_check_filetype( $args['path'] );

    		/*
    		 * If $file_info['type'] is false, then we let the editor attempt to
    		 * figure out the file type, rather than forcing a failure based on extension.
    		 */
    		if ( isset( $file_info ) && $file_info['type'] ) {
    			$args['mime_type'] = $file_info['type'];
    		}
    	}

    	// Check and set the output mime type mapped to the input type.
    	if ( isset( $args['mime_type'] ) ) {
    		$output_format = wp_get_image_editor_output_format( $path, $args['mime_type'] );
    		if ( isset( $output_format[ $args['mime_type'] ] ) ) {
    			$args['output_mime_type'] = $output_format[ $args['mime_type'] ];
    		}
    	}

    	$implementation = _wp_image_editor_choose( $args );

    	if ( $implementation ) {
    		$editor = new $implementation( $path );
    		$loaded = $editor->load();

    		if ( is_wp_error( $loaded ) ) {
    			return $loaded;
    		}

    		return $editor;
    	}

    	return new WP_Error( 'image_no_editor', __( 'No editor could be selected.' ) );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/media.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/media.php#L4354)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/media.php#L4354-L4392)

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

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

Determines the output format for the image editor.

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

Retrieves the file type from the file name.

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

Retrieves the translation of $text.

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

Checks whether the given variable is a WordPress Error.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

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

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

Allows PHP’s getimagesize() to be debuggable when necessary.

  | 
| [WP_REST_Attachments_Controller::edit_media_item()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/edit_media_item/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Applies edits to a media item and creates a new attachment record.

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

Creates image sub-sizes, adds the new data to the image meta `sizes` array, and updates the image metadata.

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

Low-level function to create image sub-sizes.

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

Streams image in post to browser, along with enqueued changes in `$_REQUEST['history']`.

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

Saves image to post, along with enqueued changes in `$_REQUEST['history']`.

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

Generates attachment meta data and create image sub-sizes for images.

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

Crops an image to a given size.

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

Scale down an image to fit a particular size and save a new copy of the image.

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

Resizes an image to make a thumbnail or intermediate size.

  |

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

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

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

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_get_image_editor/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/wp_get_image_editor/?output_format=md#comment-content-1047)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_get_image_editor/#comment-1047)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_image_editor%2F%23comment-1047)
     Vote results for this note: 5[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_image_editor%2F%23comment-1047)
 4.  **Basic Example**
 5.      ```php
         $image = wp_get_image_editor( 'cool_image.jpg' );
         if ( ! is_wp_error( $image ) ) {
             $image->rotate( 90 );
             $image->resize( 300, 300, true );
             $image->save( 'new_image.jpg' );
         }
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_image_editor%2F%3Freplytocom%3D1047%23feedback-editor-1047)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_get_image_editor/?output_format=md#comment-content-7266)
 8.    [Hyppolite T.](https://profiles.wordpress.org/hyppolitak/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/wp_get_image_editor/#comment-7266)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_image_editor%2F%23comment-7266)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_image_editor%2F%23comment-7266)
 10. **Example:** Check a broken image
 11.     ```php
         $image = wp_get_image_editor( 'my_image.jpg' );
         if ( is_wp_error( $image ) ) {
           //do some action, like add image path and name to an array of broken images.
         }
         ```
     
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_image_editor%2F%3Freplytocom%3D7266%23feedback-editor-7266)

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