用JS获取图片尺寸

JS代码如下:

1 function getFileSize(filePath){
2  var image=new Image();
3 image.dynsrc=filePath;
4 alert(image.fileSize);
5 }

上面是图片的大小

IE7下不支持属性dynsrc,可以用src代替

 

也可以获取图片的长度与宽度

 

1 function PreviewImg(imgFile){
2 var image=new Image();
3 image.src=imgFile.value;
4 imgDiv.style.width = image.width;
5 imgDiv.style.height = image.height;
6 }

 

调试:

<input name="file" size="30" type="file" onchange="getFileSize(this.value)" />

 

在IE6中运行正常,不过在IE7,IE8中还是有问题,还未找到解决方案
转自http://jiachen.blogbus.com/logs/34148035.html

posted @ 2010-03-04 14:27  poisson_notes  阅读(28851)  评论(2编辑  收藏  举报