【问题标题】:File size of image in WordpressWordpress 中图像的文件大小
【发布时间】:2014-09-23 06:20:00
【问题描述】:

我需要在 Wordpress 中计算图像的文件大小。我用这个函数检索图像 url:

$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );

<?php echo $image[0]; ?>

我打印图片网址。

如何检索文件大小并打印?

Here 是 feed-rss2.php 文件

谢谢

【问题讨论】:

    标签: php wordpress image-processing rss filesize


    【解决方案1】:

    这应该可行:

    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
    $img = get_headers($image[0], 1);
    echo $img["Content-Length"]/1024;
    

    上面将以kb为单位打印图像的大小。

    【讨论】:

    • 是的,它有效!但我需要它以字节为单位,我忘了提到它
    • 删除“/1024”以按字节显示。
    • 我会纠正我,它没有显示确切的大小。它输出一个不是大小的数字。正如您在此处看到的:primapaginaonline.it/feed 在源代码中, 标签的长度参数是正在打印的内容
    • 当我将上述代码与primapaginaonline.it/wp-content/uploads/2014/07/… 一起使用时,该图像显示 122127 字节。
    • 好吧,我不知道该说什么,我将使用输出 rss 提要的 feed-rss2.php 文件的代码编辑第一篇文章
    猜你喜欢
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-01
    • 2013-06-20
    • 2013-12-15
    • 1970-01-01
    相关资源
    最近更新 更多