您的当前位置:首页 > 知识博客 > wordpress建站

WordPress生成附件Meta数据函数:wp_generate_attachment_metadata

时间: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()


欢迎咨询/Welcome to inquire
tel/vx:18842938855
qq:1685522781
email:1685522781@qq.com

Copyright © 2019-2024 jsp.hk


Whatsapp