On this page
WP_Image_Editor_Imagick::write_image( Imagick $image, string $filename ): true|WP_Error
This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
Writes an image to a file or stream.
Parameters
$imageImagick Required$filenamestring Required-
The destination filename or stream URL.
Return
true|WP_Error
Source
File: wp-includes/class-wp-image-editor-imagick.php. View all references
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 );
}
}
}
Related
Uses
| Uses | Description |
|---|---|
| wp_is_stream() wp-includes/functions.php | Tests if a given path is a stream URL |
| wp_mkdir_p() wp-includes/functions.php | Recursive directory creation based on full path. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| esc_html() wp-includes/formatting.php | Escaping for HTML blocks. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Used By
| Used By | Description |
|---|---|
| WP_Image_Editor_Imagick::_save() wp-includes/class-wp-image-editor-imagick.php |
Changelog
| Version | Description |
|---|---|
| 5.6.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/write_image