钩子文档

image_editor_output_format

💡 云策文档标注

概述

image_editor_output_format 过滤器用于修改图像编辑器输出格式的映射关系,允许开发者自定义图像保存时的 MIME 类型转换。默认情况下,HEIC/HEIF 图像会被转换为 JPEG。

关键要点

  • 过滤器名称:image_editor_output_format
  • 作用:过滤图像编辑器输出格式的映射数组,控制源 MIME 类型到目标 MIME 类型的转换
  • 默认行为:将 HEIC/HEIF 输入映射为 JPEG 输出(从 WordPress 6.7.0 开始)
  • 相关函数:WP_Image_Editor::get_output_format() 和 wp_get_image_editor_output_format()
  • 引入版本:WordPress 5.8.0

代码示例

function map_jpeg_to_webp( $mappings ) {
    $mappings[ 'image/jpeg' ] = 'image/webp';
    return $mappings;
};
add_filter( 'image_editor_output_format', 'map_jpeg_to_webp' );

📄 原文内容

Filters the image editor output format mapping.

Description

Enables filtering the mime type used to save images. By default HEIC/HEIF images are converted to JPEGs.

See also

Parameters

$output_formatstring[]
An array of mime type mappings. Maps a source mime type to a new destination mime type. By default maps HEIC/HEIF input to JPEG output.

  • ...$0 string
    The new mime type.

$filenamestring
Path to the image.
$mime_typestring
The source image mime type.

Source

return apply_filters( 'image_editor_output_format', $output_format, $filename, $mime_type );

Changelog

Version Description
6.7.0 The default was changed from an empty array to an array containing the HEIC/HEIF images mime types.
5.8.0 Introduced.

User Contributed Notes