WP_Image_Editor_Imagick::_save( Imagick $image, string $filename = null, string $mime_type = null )
Parameters
- $image
-
(Required)
- $filename
-
(Optional)
Default value: null
- $mime_type
-
(Optional)
Default value: null
Return
(array|WP_Error) Array on success or WP_Error if the file failed to save.<br>
- 'path'
(string) Path to the image file.<br> - 'file'
(string) Name of the image file.<br> - 'width'
(int) Image width.<br> - 'height'
(int) Image height.<br> - 'mime-type'
(string) The mime type of the image.<br> - 'filesize'
(int) File size of the image.<br>
Source
File: wp-includes/class-wp-image-editor-imagick.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 ) ) );
$this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) );
// Reset original Format
$this->image->setImageFormat( $orig_format );
}
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 );
/** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
return array(
'path' => $filename,
'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
'width' => $this->size['width'],
'height' => $this->size['height'],
'mime-type' => $mime_type,
);
}
Changelog
Version | Description |
---|---|
6.0.0 | The $filesize value was added to the returned array. |
3.5.0 | Introduced. |