简体   繁体   中英

Determine image size in pixels using javascript

我想在asp.net的文件上传控件中将图片上传之前比较为x x y像素,如何使用JavaScript在File Uploader中获取以像素为单位的图像大小?

One way to get the image sizes in javascript is to do the following:

var img = document.getElementById('yourimageId'); 

var width = img.clientWidth;
var height = img.clientHeight;

Also have a look at the following answer to a similar previous question:

in firefox ,you can get the file's path by this method:

https://developer.mozilla.org/en/DOM/File.getAsDataURL

or latest version :

window.URL.createObjectURL(file);

for webkit window.webkitURL.createObjectURL() see https://developer.mozilla.org/en/Document_Object_Model_(DOM)/window.URL.createObjectURL

and set it to a img tag and get the size.
for ie, you shoule set a filter to the elem

progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image)

and set the url to this filter then you can get the img's size good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM