原始图像的宽度

时间:2013-08-21 15:36:59

标签: javascript jquery image-processing

快速提问。

我试图在服务器上找到存储图像的宽度和高度,以便将其加载到jcrop功能中。

页面上显示的图像是可调整大小的,因此不代表原始图像的适当尺寸,所以当我试图将其复制时,合作者就错了

有没有办法使用jquery或javascript找到原始的高度和宽度。

更新

我已经制作了一些我需要的东西,不起作用,任何人都可以看到它为什么不起作用http://jsfiddle.net/2C2Eu/2/

function getimagesize(img) {
img.onload = function () {
    alert(this.width + 'x' + this.height);
};
}

var image = "http://www.citizenship-aei.org/wp-content/uploads/Testing.jpg";
getimagesize(image);

2 个答案:

答案 0 :(得分:3)

在页面上加载图像并阅读尺寸。

var img = new Image();
img.onload = function() {
    var width = img.width;
    var height = img.height;
    processImage(img, width, height); //call some function
}
img.src = "foo.png";

答案 1 :(得分:1)

function GetAnImage(src) {

    var newImg = document.createElement('img');
    newImg.src = src;

    return newImg;
}

var newImg = GetAnImage("abc.jpg");
newImg.onload = function () {                           
    var height = this.height;
    var width = this.width;  
    //do with the image as you want         
}

我希望它有所帮助。