getimagesize_mimes_to_exts
云策文档标注
概述
本文档介绍 WordPress 中的 getimagesize_mimes_to_exts 过滤器,用于映射图像 MIME 类型到对应的文件扩展名。开发者可以通过此过滤器自定义或扩展图像类型与扩展名的关联关系。
关键要点
- getimagesize_mimes_to_exts 是一个过滤器,允许修改图像 MIME 类型到扩展名的映射数组。
- 参数 $mime_to_ext 是一个数组,键为图像 MIME 类型(如 'image/jpeg'),值为对应的文件扩展名(如 'jpg')。
- 此过滤器在 wp_check_filetype_and_ext() 函数中使用,用于确定文件的真实类型。
- 自 WordPress 3.0.0 版本引入。
代码示例
$mime_to_ext = apply_filters(
'getimagesize_mimes_to_exts',
array(
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/tiff' => 'tif',
'image/webp' => 'webp',
'image/avif' => 'avif',
'image/heic' => 'heic',
'image/heif' => 'heic',
'image/heic-sequence' => 'heic',
'image/heif-sequence' => 'heic',
)
);
原文内容
Filters the list mapping image mime types to their respective extensions.
Parameters
$mime_to_extarray-
Array of image mime types and their matching extensions.
Source
$mime_to_ext = apply_filters(
'getimagesize_mimes_to_exts',
array(
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/gif' => 'gif',
'image/bmp' => 'bmp',
'image/tiff' => 'tif',
'image/webp' => 'webp',
'image/avif' => 'avif',
/*
* In theory there are/should be file extensions that correspond to the
* mime types: .heif, .heics and .heifs. However it seems that HEIC images
* with any of the mime types commonly have a .heic file extension.
* Seems keeping the status quo here is best for compatibility.
*/
'image/heic' => 'heic',
'image/heif' => 'heic',
'image/heic-sequence' => 'heic',
'image/heif-sequence' => 'heic',
)
);
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |