fas
fas

Reputation: 103

File size of image in Wordpress

I need to calculate the file size of an image in Wordpress. I retrive the image url with this function:

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

and with

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

I print the image url.

How can I do to retrieve the filesize and to print it?

Here is the feed-rss2.php file

Thanks

Upvotes: 0

Views: 2451

Answers (2)

AbdulAhmad Matin
AbdulAhmad Matin

Reputation: 1146

You can also use

echo filesize(get_attached_file($image->ID)).'Bytes';

Upvotes: 0

Howli
Howli

Reputation: 12469

This should work:

$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;

The above will print the size of the image in kb.

Upvotes: 1

Related Questions