wp_save_image_file( string $filename, WP_Image_Editor $image, string $mime_type, int $post_id )
Saves Image to File
Parameters
- $filename
-
(Required)
- $image
-
(Required)
- $mime_type
-
(Required)
- $post_id
-
(Required)
Return
(bool)
Source
File: wp-admin/includes/image-edit.php
function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
if ( $image instanceof WP_Image_Editor ) {
/** This filter is documented in wp-admin/includes/image-edit.php */
$image = apply_filters( 'image_editor_save_pre', $image, $post_id );
/**
* Filters whether to skip saving the image file.
*
* Returning a non-null value will short-circuit the save method,
* returning that value instead.
*
* @since WP-3.5.0
*
* @param mixed $override Value to return instead of saving. Default null.
* @param string $filename Name of the file to be saved.
* @param WP_Image_Editor $image WP_Image_Editor instance.
* @param string $mime_type Image mime type.
* @param int $post_id Post ID.
*/
$saved = apply_filters( 'wp_save_image_editor_file', null, $filename, $image, $mime_type, $post_id );
if ( null !== $saved )
return $saved;
return $image->save( $filename, $mime_type );
} else {
_deprecated_argument( __FUNCTION__, 'WP-3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
/** This filter is documented in wp-admin/includes/image-edit.php */
$image = apply_filters( 'image_save_pre', $image, $post_id );
/**
* Filters whether to skip saving the image file.
*
* Returning a non-null value will short-circuit the save method,
* returning that value instead.
*
* @since WP-2.9.0
* @deprecated WP-3.5.0 Use wp_save_image_editor_file instead.
*
* @param mixed $override Value to return instead of saving. Default null.
* @param string $filename Name of the file to be saved.
* @param WP_Image_Editor $image WP_Image_Editor instance.
* @param string $mime_type Image mime type.
* @param int $post_id Post ID.
*/
$saved = apply_filters( 'wp_save_image_file', null, $filename, $image, $mime_type, $post_id );
if ( null !== $saved )
return $saved;
switch ( $mime_type ) {
case 'image/jpeg':
/** This filter is documented in wp-includes/class-wp-image-editor.php */
return imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) );
case 'image/png':
return imagepng( $image, $filename );
case 'image/gif':
return imagegif( $image, $filename );
default:
return false;
}
}
}