Get True Dimensions of an Image with JQuery

后端 未结 1 851
时光取名叫无心
时光取名叫无心 2021-01-14 18:09

Given a list of image paths how can I iterate through them and find the actual image dimensions? I assume I have to insert them into the DOM without width or height propert

1条回答
  •  不思量自难忘°
    2021-01-14 18:50

    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;
    
    });
    

    See it on jsFiddle.

    0 讨论(0)
提交回复
热议问题