Good evening,
I'm using a material-ui Card inside a React functional component, with a CardMedia such as :
<CardMedia
className={classes.media}
image={props.image}
title={props.cardTitle}
/>
I'm trying to determine the image file size in bytes. After some research I found solutions which use XMLHttpRequest. It seems strange to me to download the file again. I found how to get the image width and height using :
function checkImage() {
var img = new Image();
img.addEventListener("load", function(){
console.log( this.naturalWidth +' '+ this.naturalHeight );
});
img.src = props.image;
}
It works, but this is not what I'm looking for and if I'm not mistaken this downloads the image again. I looked into Mozilla doc, Image
only has width and height properties. Since the image is already loaded, I should have a way to determine its size in byte without using XMLHttpRequest ?