WP_Image_Editor::save( string $destfilename = null, string $mime_type = null ): array|WP_Error

Saves current image to file.


$destfilename string Optional
Destination filename.

Default: null

$mime_type string Optional
The mime-type.

Default: null

Top ↑


array|WP_Error Array on success or WP_Error if the file failed to save.

  • path string
    Path to the image file.
  • file string
    Name of the image file.
  • width int
    Image width.
  • height int
    Image height.
  • mime-type string
    The mime type of the image.
  • filesize int
    File size of the image.

Top ↑


File: wp-includes/class-wp-image-editor.php. View all references

abstract public function save( $destfilename = null, $mime_type = null );

Top ↑


Version Description
6.0.0 The $filesize value was added to the returned array.
3.5.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by thomasmathys

    Uppercase extension

    Due to the presence of a strtolower in WP_Image_Editor::generate_filename, there can be issues with uppercase file extensions on linux-like system.

    $image = wp_get_image_editor( 'path/to/SOURCE.JPG' );
    $image->save( 'path/to/TARGET.JPG' );
    if ( file_exists ( 'path/to/TARGET.JPG' ) ) {
    	echo 'This will NOT show';
    if ( file_exists ( 'path/to/TARGET.jpg' ) ) {
    	echo 'This WILL show';

You must log in before being able to contribute a note or feedback.