WordPress at a glance
function is not described

WP_Image_Editor_Imagick::write_image() private WP 5.6.0

Writes an image to a file or stream.

{} It's a method of the class: WP_Image_Editor_Imagick{}

No Hooks.

Return

true|WP_Error.

Usage

// private - for code of main (parent) class only
$result = $this->write_image( $image, $filename );
$image(Imagick) (required)
-
$filename(string) (required)
The destination filename or stream URL.

Changelog

Since 5.6.0 Introduced.

Code of WP_Image_Editor_Imagick::write_image() WP 5.7.2

<?php
private function write_image( $image, $filename ) {
	if ( wp_is_stream( $filename ) ) {
		/*
		 * Due to reports of issues with streams with `Imagick::writeImageFile()` and `Imagick::writeImage()`, copies the blob instead.
		 * Checks for exact type due to: https://www.php.net/manual/en/function.file-put-contents.php
		 */
		if ( file_put_contents( $filename, $image->getImageBlob() ) === false ) {
			return new WP_Error(
				'image_save_error',
				sprintf(
					/* translators: %s: PHP function name. */
					__( '%s failed while writing image to stream.' ),
					'<code>file_put_contents()</code>'
				),
				$filename
			);
		} else {
			return true;
		}
	} else {
		$dirname = dirname( $filename );

		if ( ! wp_mkdir_p( $dirname ) ) {
			return new WP_Error(
				'image_save_error',
				sprintf(
					/* translators: %s: Directory path. */
					__( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
					esc_html( $dirname )
				)
			);
		}

		try {
			return $image->writeImage( $filename );
		} catch ( Exception $e ) {
			return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
		}
	}
}