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

---

# WP_Image_Editor_Imagick::_save( Imagick $image, string $filename = null, string $mime_type = null ): array|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

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

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

 `$image`Imagickrequired

`$filename`stringoptional

Default:`null`

`$mime_type`stringoptional

Default:`null`

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

 array|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) Array
on success or [WP_Error](https://developer.wordpress.org/reference/classes/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.

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

    ```php
    protected function _save( $image, $filename = null, $mime_type = null ) {
    	list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type );

    	if ( ! $filename ) {
    		$filename = $this->generate_filename( null, null, $extension );
    	}

    	try {
    		// Store initial format.
    		$orig_format = $this->image->getImageFormat();

    		$this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) );
    	} catch ( Exception $e ) {
    		return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
    	}

    	if ( method_exists( $this->image, 'setInterlaceScheme' )
    		&& method_exists( $this->image, 'getInterlaceScheme' )
    		&& defined( 'Imagick::INTERLACE_PLANE' )
    	) {
    		$orig_interlace = $this->image->getInterlaceScheme();

    		/** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
    		if ( apply_filters( 'image_save_progressive', false, $mime_type ) ) {
    			$this->image->setInterlaceScheme( Imagick::INTERLACE_PLANE ); // True - line interlace output.
    		} else {
    			$this->image->setInterlaceScheme( Imagick::INTERLACE_NO ); // False - no interlace output.
    		}
    	}

    	$write_image_result = $this->write_image( $this->image, $filename );
    	if ( is_wp_error( $write_image_result ) ) {
    		return $write_image_result;
    	}

    	try {
    		// Reset original format.
    		$this->image->setImageFormat( $orig_format );

    		if ( isset( $orig_interlace ) ) {
    			$this->image->setInterlaceScheme( $orig_interlace );
    		}
    	} catch ( Exception $e ) {
    		return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
    	}

    	// Set correct file permissions.
    	$stat  = stat( dirname( $filename ) );
    	$perms = $stat['mode'] & 0000666; // Same permissions as parent folder, strip off the executable bits.
    	chmod( $filename, $perms );

    	return array(
    		'path'      => $filename,
    		/** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
    		'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
    		'width'     => $this->size['width'],
    		'height'    => $this->size['height'],
    		'mime-type' => $mime_type,
    		'filesize'  => wp_filesize( $filename ),
    	);
    }
    ```

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

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

 [apply_filters( ‘image_make_intermediate_size’, string $filename )](https://developer.wordpress.org/reference/hooks/image_make_intermediate_size/)

Filters the name of the saved image file.

 [apply_filters( ‘image_save_progressive’, bool $interlace, string $mime_type )](https://developer.wordpress.org/reference/hooks/image_save_progressive/)

Filters whether to output progressive images (if available).

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

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

Wrapper for PHP filesize with filters and casting the result as an integer.

  | 
| [WP_Image_Editor_Imagick::write_image()](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/write_image/)`wp-includes/class-wp-image-editor-imagick.php` |

Writes an image to a file or stream.

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

i18n-friendly version of basename().

  | 
| [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.

  | 
| [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 4 more](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/_save/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/_save/?output_format=md#)

| Used by | Description | 
| [WP_Image_Editor_Imagick::make_subsize()](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/make_subsize/)`wp-includes/class-wp-image-editor-imagick.php` |

Create an image sub-size and return the image meta data value for it.

  | 
| [WP_Image_Editor_Imagick::save()](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/save/)`wp-includes/class-wp-image-editor-imagick.php` |

Saves current image to file.

  |

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

| Version | Description | 
| [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | The `$filesize` value was added to the returned array. | 
| [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. |

## User Contributed Notes

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