WordPress生成附件Meta数据函数
WordPress函数wp_generate_attachment_metadata根据附件ID生成该附件的Meta数据,如果附件类型为图片类型,且$file参数的值不为空,该函数还会创建对应的缩略图版本。
wp_generate_attachment_metadata( int $attachment_id, string $file )
函数参数
$attachment_id
整数
附件的ID
$file
字符串
文件路径
函数返回值
Array
(
[width] => 768
[height] => 430
[file] => 2020/05/baidusrf-for-linux.webp
[sizes] => Array
(
[thumbnail] => Array
(
[file] => baidusrf-for-linux-320x200.jpg
[width] => 320
[height] => 200
[mime-type] => image/webp
)
)
[image_meta] => Array
(
[aperture] => 0
[credit] =>
[camera] =>
=>
[created_timestamp] => 0
[copyright] =>
[focal_length] => 0
[iso] => 0
[shutter_speed] => 0
[title] =>
[orientation] => 0
[keywords] => Array
(
)
)
)
函数使用示例
<?php
$attach_id = wp_insert_attachment($attachment, $filename, 37);
$attach_data = wp_generate_attachment_metadata($attach_id, $filename);
wp_update_attachment_metadata($attach_id, $attach_data);
?>
扩展阅读
wp_generate_attachment_metadata()函数位于:wp-admin/includes/image.php