在没有`<img>`标记的JavaScript中确定图像大小

Ric*_*uen 5 javascript ajax image

使用JavaScript,如何在不将文档插入文档的情况下确定文档中没有的图像大小?

我可以使用AJAX下载图像并以编程方式检查其高度和宽度吗?

就像是...

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var imageSize = MEGIC_GET_FILE_SIZE_FUNCTION(xmlhttp);
        alert("The image is "+imageSize.width+","+imageSize.height+".");
    }
}
xmlhttp.open("GET","lena.jpg",true);
xmlhttp.send();
Run Code Online (Sandbox Code Playgroud)

我将使用拉斐尔,所以如果它提供这种效果的功能,那就适合我的需要.

Bal*_*usC 8

你不需要ajax.

var img = new Image();
img.onload = function() {
    alert("The image is " + this.width + "x" + this.height);
}
img.src = "lena.jpg";
Run Code Online (Sandbox Code Playgroud)