WP_Image_Editor_Imagick::save PHP Method

save() public method

Saves current image to file.
Since: 3.5.0
public save ( string $destfilename = null, string $mime_type = null ) : array | WP_Error
$destfilename string
$mime_type string
return array | WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string}
    public function save($destfilename = null, $mime_type = null)
    {
        $saved = $this->_save($this->image, $destfilename, $mime_type);
        if (!is_wp_error($saved)) {
            $this->file = $saved['path'];
            $this->mime_type = $saved['mime-type'];
            try {
                $this->image->setImageFormat(strtoupper($this->get_extension($this->mime_type)));
            } catch (Exception $e) {
                return new WP_Error('image_save_error', $e->getMessage(), $this->file);
            }
        }
        return $saved;
    }

Usage Example

 /**
  * It's expected that we can't save image uses imagick built in, as
  * the undlaying system library can't write to the "s3://" filesystem.
  *
  */
 public function test_save_image_with_inbuilt_fails()
 {
     $upload_dir = wp_upload_dir();
     $path = $upload_dir['basedir'] . '/canola.jpg';
     copy($this->image_path, $path);
     $image_editor = new WP_Image_Editor_Imagick($path);
     $image_editor->load();
     $status = $image_editor->save($upload_dir['basedir'] . '/canola-100x100.jpg');
     $this->assertWPError($status);
 }