【发布时间】:2013-09-10 15:37:38
【问题描述】:
我正在使用 ajax 调用从服务器接收长字符串中的图像
图片的url肯定在result[1]里面。 我使用了 width/naturalWidth 和 height/naturalHeight,有时它们会返回 0,而在其他情况下,它们会返回正确的像素大小
var imgElement = jQuery("<img>").attr("src", result[1]);
var width = imgElement[0].naturalWidth;
var height = imgElement[0].naturalHeight;
if (width >= that.minImgPixels && height >= that.minImgPixels) {
image = result[1];
}
如何在不插入到 dom 的情况下检查图像宽度和高度的正确方法?
【问题讨论】:
-
这个对类似问题的回答向您展示了如何在 javascript 中以编程方式创建图像,而不必先在 dom 中:stackoverflow.com/a/626505/1805956
标签: javascript jquery