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

In this article

Saves current in-memory image to file.

Parameters

$destfilenamestring|nulloptional
Destination filename.

Default:null

$mime_typestring|nulloptional
The mime-type.

Default:null

Return

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.

Source

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'];
	}

	return $saved;
}

Changelog

VersionDescription
6.0.0The $filesize value was added to the returned array.
5.9.0Renamed $filename to $destfilename to match parent class for PHP 8 named parameter support.
3.5.0Introduced.

User Contributed Notes

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