wp_save_image_file

The timeline below displays how wordpress function wp_save_image_file has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Saves image to file.
 *
 * @since 2.9.0
 * @since 3.5.0 The `$image` parameter expects a `WP_Image_Editor` instance.
 * @since 6.0.0 The `$filesize` value was added to the returned array.
 *
 * @param string          $filename  Name of the file to be saved.
 * @param WP_Image_Editor $image     The image editor instance.
 * @param string          $mime_type The mime type of the image.
 * @param int             $post_id   Attachment post ID.
 * @return array|WP_Error|bool {
 *     Array on success or WP_Error if the file failed to save.
 *     When called with a deprecated value for the `$image` parameter,
 *     i.e. a non-`WP_Image_Editor` image resource or `GdImage` instance,
 *     the function will return true on success, false on failure.
 *
 *     @type string $path      Path to the image file.
 *     @type string $file      Name of the image file.
 *     @type int    $width     Image width.
 *     @type int    $height    Image height.
 *     @type string $mime-type The mime type of the image.
 *     @type int    $filesize  File size of the image.
 * }
 */
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 3.5.0
         *
         * @param bool|null       $override  Value to return instead of saving. Default null.
         * @param string          $filename  Name of the file to be saved.
         * @param WP_Image_Editor $image     The image editor instance.
         * @param string          $mime_type The mime type of the image.
         * @param int             $post_id   Attachment 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 {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /** This filter is documented in wp-admin/includes/image-edit.php */
        $image = apply_filters_deprecated('image_save_pre', array($image, $post_id), '3.5.0', 'image_editor_save_pre');
        /**
         * Filters whether to skip saving the image file.
         *
         * Returning a non-null value will short-circuit the save method,
         * returning that value instead.
         *
         * @since 2.9.0
         * @deprecated 3.5.0 Use {@see 'wp_save_image_editor_file'} instead.
         *
         * @param bool|null        $override  Value to return instead of saving. Default null.
         * @param string           $filename  Name of the file to be saved.
         * @param resource|GdImage $image     Image resource or GdImage instance.
         * @param string           $mime_type The mime type of the image.
         * @param int              $post_id   Attachment post ID.
         */
        $saved = apply_filters_deprecated('wp_save_image_file', array(null, $filename, $image, $mime_type, $post_id), '3.5.0', 'wp_save_image_editor_file');
        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);
            case 'image/webp':
                if (function_exists('imagewebp')) {
                    return imagewebp($image, $filename);
                }
                return false;
            case 'image/avif':
                if (function_exists('imageavif')) {
                    return imageavif($image, $filename);
                }
                return false;
            default:
                return false;
        }
    }
}

WordPress Version: 6.1

/**
 * Saves image to file.
 *
 * @since 2.9.0
 * @since 3.5.0 The `$image` parameter expects a `WP_Image_Editor` instance.
 * @since 6.0.0 The `$filesize` value was added to the returned array.
 *
 * @param string          $filename  Name of the file to be saved.
 * @param WP_Image_Editor $image     The image editor instance.
 * @param string          $mime_type The mime type of the image.
 * @param int             $post_id   Attachment post ID.
 * @return array|WP_Error|bool {
 *     Array on success or WP_Error if the file failed to save.
 *     When called with a deprecated value for the `$image` parameter,
 *     i.e. a non-`WP_Image_Editor` image resource or `GdImage` instance,
 *     the function will return true on success, false on failure.
 *
 *     @type string $path      Path to the image file.
 *     @type string $file      Name of the image file.
 *     @type int    $width     Image width.
 *     @type int    $height    Image height.
 *     @type string $mime-type The mime type of the image.
 *     @type int    $filesize  File size of the image.
 * }
 */
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 3.5.0
         *
         * @param bool|null       $override  Value to return instead of saving. Default null.
         * @param string          $filename  Name of the file to be saved.
         * @param WP_Image_Editor $image     The image editor instance.
         * @param string          $mime_type The mime type of the image.
         * @param int             $post_id   Attachment 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 {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /** This filter is documented in wp-admin/includes/image-edit.php */
        $image = apply_filters_deprecated('image_save_pre', array($image, $post_id), '3.5.0', 'image_editor_save_pre');
        /**
         * Filters whether to skip saving the image file.
         *
         * Returning a non-null value will short-circuit the save method,
         * returning that value instead.
         *
         * @since 2.9.0
         * @deprecated 3.5.0 Use {@see 'wp_save_image_editor_file'} instead.
         *
         * @param bool|null        $override  Value to return instead of saving. Default null.
         * @param string           $filename  Name of the file to be saved.
         * @param resource|GdImage $image     Image resource or GdImage instance.
         * @param string           $mime_type The mime type of the image.
         * @param int              $post_id   Attachment post ID.
         */
        $saved = apply_filters_deprecated('wp_save_image_file', array(null, $filename, $image, $mime_type, $post_id), '3.5.0', 'wp_save_image_editor_file');
        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);
            case 'image/webp':
                if (function_exists('imagewebp')) {
                    return imagewebp($image, $filename);
                }
                return false;
            default:
                return false;
        }
    }
}

WordPress Version: 5.9

/**
 * Saves image to file.
 *
 * @since 2.9.0
 *
 * @param string          $filename  Name of the file to be saved.
 * @param WP_Image_Editor $image     The image editor instance.
 * @param string          $mime_type The mime type of the image.
 * @param int             $post_id   Attachment post ID.
 * @return bool True on success, false on failure.
 */
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 3.5.0
         *
         * @param bool|null       $override  Value to return instead of saving. Default null.
         * @param string          $filename  Name of the file to be saved.
         * @param WP_Image_Editor $image     The image editor instance.
         * @param string          $mime_type The mime type of the image.
         * @param int             $post_id   Attachment 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 {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /** This filter is documented in wp-admin/includes/image-edit.php */
        $image = apply_filters_deprecated('image_save_pre', array($image, $post_id), '3.5.0', 'image_editor_save_pre');
        /**
         * Filters whether to skip saving the image file.
         *
         * Returning a non-null value will short-circuit the save method,
         * returning that value instead.
         *
         * @since 2.9.0
         * @deprecated 3.5.0 Use {@see 'wp_save_image_editor_file'} instead.
         *
         * @param bool|null        $override  Value to return instead of saving. Default null.
         * @param string           $filename  Name of the file to be saved.
         * @param resource|GdImage $image     Image resource or GdImage instance.
         * @param string           $mime_type The mime type of the image.
         * @param int              $post_id   Attachment post ID.
         */
        $saved = apply_filters_deprecated('wp_save_image_file', array(null, $filename, $image, $mime_type, $post_id), '3.5.0', 'wp_save_image_editor_file');
        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);
            case 'image/webp':
                if (function_exists('imagewebp')) {
                    return imagewebp($image, $filename);
                }
                return false;
            default:
                return false;
        }
    }
}

WordPress Version: 5.8

/**
 * Saves image to file.
 *
 * @since 2.9.0
 *
 * @param string          $filename  Name of the file to be saved.
 * @param WP_Image_Editor $image     The image editor instance.
 * @param string          $mime_type The mime type of the image.
 * @param int             $post_id   Attachment post ID.
 * @return bool True on success, false on failure.
 */
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 3.5.0
         *
         * @param bool|null       $override  Value to return instead of saving. Default null.
         * @param string          $filename  Name of the file to be saved.
         * @param WP_Image_Editor $image     The image editor instance.
         * @param string          $mime_type The mime type of the image.
         * @param int             $post_id   Attachment 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 {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /** This filter is documented in wp-admin/includes/image-edit.php */
        $image = apply_filters_deprecated('image_save_pre', array($image, $post_id), '3.5.0', 'image_editor_save_pre');
        /**
         * Filters whether to skip saving the image file.
         *
         * Returning a non-null value will short-circuit the save method,
         * returning that value instead.
         *
         * @since 2.9.0
         * @deprecated 3.5.0 Use {@see '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     The image editor instance.
         * @param string          $mime_type The mime type of the image.
         * @param int             $post_id   Attachment post ID.
         */
        $saved = apply_filters_deprecated('wp_save_image_file', array(null, $filename, $image, $mime_type, $post_id), '3.5.0', 'wp_save_image_editor_file');
        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);
            case 'image/webp':
                if (function_exists('imagewebp')) {
                    return imagewebp($image, $filename);
                }
                return false;
            default:
                return false;
        }
    }
}

WordPress Version: 5.4

/**
 * Saves image to file.
 *
 * @since 2.9.0
 *
 * @param string          $filename  Name of the file to be saved.
 * @param WP_Image_Editor $image     The image editor instance.
 * @param string          $mime_type The mime type of the image.
 * @param int             $post_id   Attachment post ID.
 * @return bool True on success, false on failure.
 */
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 3.5.0
         *
         * @param bool|null       $override  Value to return instead of saving. Default null.
         * @param string          $filename  Name of the file to be saved.
         * @param WP_Image_Editor $image     The image editor instance.
         * @param string          $mime_type The mime type of the image.
         * @param int             $post_id   Attachment 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 {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /** This filter is documented in wp-admin/includes/image-edit.php */
        $image = apply_filters_deprecated('image_save_pre', array($image, $post_id), '3.5.0', 'image_editor_save_pre');
        /**
         * Filters whether to skip saving the image file.
         *
         * Returning a non-null value will short-circuit the save method,
         * returning that value instead.
         *
         * @since 2.9.0
         * @deprecated 3.5.0 Use {@see '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     The image editor instance.
         * @param string          $mime_type The mime type of the image.
         * @param int             $post_id   Attachment post ID.
         */
        $saved = apply_filters_deprecated('wp_save_image_file', array(null, $filename, $image, $mime_type, $post_id), '3.5.0', 'wp_save_image_editor_file');
        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;
        }
    }
}

WordPress Version: 5.3

/**
 * Saves image to file.
 *
 * @since 2.9.0
 *
 * @param string $filename
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return bool
 */
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 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 {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /** 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 2.9.0
         * @deprecated 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;
        }
    }
}

WordPress Version: 5.1

/**
 * Saves image to file.
 *
 * @since 2.9.0
 *
 * @param string $filename
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return bool
 */
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 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__, '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 2.9.0
         * @deprecated 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;
        }
    }
}

WordPress Version: 4.6

/**
 * Saves Image to File
 *
 * @param string $filename
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return bool
 */
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 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__, '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 2.9.0
         * @deprecated 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;
        }
    }
}

WordPress Version: 4.3

/**
 * Saves Image to File
 *
 * @param string $filename
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return bool
 */
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);
        /**
         * Filter whether to skip saving the image file.
         *
         * Returning a non-null value will short-circuit the save method,
         * returning that value instead.
         *
         * @since 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__, '3.5', __('$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);
        /**
         * Filter whether to skip saving the image file.
         *
         * Returning a non-null value will short-circuit the save method,
         * returning that value instead.
         *
         * @since 2.9.0
         * @deprecated 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;
        }
    }
}

WordPress Version: 3.9

/**
 * Saves Image to File
 *
 * @param string $filename
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return boolean
 */
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);
        /**
         * Filter whether to skip saving the image file.
         *
         * Returning a non-null value will short-circuit the save method,
         * returning that value instead.
         *
         * @since 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__, '3.5', __('$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);
        /**
         * Filter whether to skip saving the image file.
         *
         * Returning a non-null value will short-circuit the save method,
         * returning that value instead.
         *
         * @since 2.9.0
         * @deprecated 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;
        }
    }
}

WordPress Version: 3.8

/**
 * Saves Image to File
 *
 * @param string $filename
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return boolean
 */
function wp_save_image_file($filename, $image, $mime_type, $post_id)
{
    if ($image instanceof WP_Image_Editor) {
        $image = apply_filters('image_editor_save_pre', $image, $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__, '3.5', __('$image needs to be an WP_Image_Editor object'));
        $image = apply_filters('image_save_pre', $image, $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;
        }
    }
}

WordPress Version: 3.7

/**
 * Saves Image to File
 *
 * @param string $filename
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return boolean
 */
function wp_save_image_file($filename, $image, $mime_type, $post_id)
{
    if ($image instanceof WP_Image_Editor) {
        $image = apply_filters('image_editor_save_pre', $image, $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__, '3.5', __('$image needs to be an WP_Image_Editor object'));
        $image = apply_filters('image_save_pre', $image, $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':
                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;
        }
    }
}