Get true image sizes using jQuery

Given the list of image paths, how can I iterate over them and find the actual image sizes? I assume that I need to insert them into the DOM without the width or height properties and make .width and .height on them?

+3
source share
1 answer
var paths = ['/path/image.png', 'somewhere/page.jpg']; $.each(paths, function(i, path) { var img = new Image(); $(img).load(function() { var width = img.width, height = img.height; alert(width + ' Γ— ' + height); }); img.src = path; }); 

Take a look at jsFiddle .

+4
source

Source: https://habr.com/ru/post/1334726/


All Articles