在表单提交之前获取上载图像的图像高度和宽度 [英] To get image height and width of uploaded image before form submission

查看:106
本文介绍了在表单提交之前获取上载图像的图像高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery或Javascript获取上传图片的高度和宽度表单提交

How to get an uploaded image's height and width before form submission, using jQuery or Javascript?

<input type="file" />

我需要检查要上传的图像的宽度和高度是否等于所选宽度和身高。我找到了此链接。但它只适用于FF和Chrome,而不适用于IE7和IE8。

I need to check whether the width and height of the image to be uploaded are equal to the selected width and height. I have found this link. But it's only working for FF and Chrome, not in IE7 and IE8.

任何人都可以通过任何其他方式获取尺寸,以便它可以在所有浏览器中使用吗? / p>

Can anyone show me any other way to get the dimensions so that it's working in all browsers?

推荐答案

您可以创建图像对象,创建图像对象后,从图像标签中获取图像,该图像标签显示要上载的图像然后你可以通过下面的方法得到图像的维度。

You can create an image object, After creating image object get the image from the image tag which is showing the image to be uploaded and then you can get the dimension of the image by following method written ahead.

var v=new Image();
v.src=document.getElementById("up_img").getAttribute('src');
alert(v.width);

请记住,你必须使用Base64方法才能让图像显示在图片标签中,我不知道它是否受支持,但它是Chrome,Firefox,Opera中的HTML5工具。

Remember you will have to use the Base64 method to get the image to be displayed in the image tag, i don't know whether it is supported in ie or not but it is the HTML5 facility available in Chrome ,Firefox, Opera.

这篇关于在表单提交之前获取上载图像的图像高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆