Images and script are hosted on the same account (one site), but we know only the URL of the image.
$image = "http://example.com/images/full-1091.jpg"
How can we get the size of this file?
Pseudo-code:
{ do something with $image and get $image_size }
echo $image_size;
I would prefer $image_size
to be formatted in human-readable file sizes, like "156,8 Kbytes" or "20,1 Mbytes".
Hover over the URL to see the pop up with all of the image properties. This pop up includes the Rendered size – the dimensions that the website needs – as well as the Intrinsic size – the dimensions of the originally image uploaded.
File size can be expressed as the resolution (the image width multiplied by the image height) multiplied by the bit depth (the number of bits needed to store colours).
You can resize images by passing a size parameter in the query string portion of the URL. The size parameter replaces the larger of the height or width parameters.
Use filesize
function like this:
echo filesize($filename) . ' bytes';
You can also format the unit of the size with this function:
function format_size($size) {
$sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
if ($size == 0) { return('n/a'); } else {
return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With