android get width and height of image from src code example
Example 1: how to get img dimensions from remote url js
function getMeta(url, callback) {
var img = new Image();
img.src = url;
img.onload = function() { callback(this.width, this.height); }
}
getMeta(
"http://snook.ca/files/mootools_83_snookca.png",
function(width, height) { alert(width + 'px ' + height + 'px') }
);
Example 2: height auto width 100% will ignore width and height
<style>
img {
width: 100%;
height: auto;
aspect-ratio: attr(width) / attr(height);
}
</style>
<img src="hero_image.jpg" alt="" width="500" height="500">