时间:2024-03-12
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
相关函数:
wp_ajax_crop_image()
wp_attachment_is()
wp_create_image_subsizes()
wp_get_registered_image_subsizes()
wp_get_attachment_metadata()
Copyright © 2019-2024 java.fit