使用javascript获取文件标记中的图像高度和宽度 [英] get image height and width in file tag using javascript

查看:118
本文介绍了使用javascript获取文件标记中的图像高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

获取文件标签javascript中的图像高度和宽度

通过Javascript确定图像文件大小+尺寸?

如何在通过JavaScript上传之前上传预览图像

如何在文件标签中没有页面刷新的情况下获得图像的高度和宽度?

how can i get the height and width of image without page refresh in file tag?

<HTML>
<HEAD>
    <TITLE></TITLE>
    <script language="javascript">
    function getW()
    {
        var theImg = document.getElementById('testimg');
        alert(theImg.width);
    }

    function getH()
    {
        var theImg = document.getElementById('testimg');
        alert(theImg.height);
    }
    </script>
</HEAD>

<BODY>        
<input type="file" id="testimg"/>
    <input type="button" value="get Width" onclick="getW()"/>
    <input type="button" value="get Height" onclick="getH()"/>
</BODY>
</HTML>

我使用php代码获取图像的图像高度和宽度,但该时间页面将被刷新,没有页面刷新我得到的图像大小,但没有高度和宽度....

i get the image height and width of image using php code, but that time page will be refreshed, without page refresh i get image size but not a height and width....

推荐答案

这是不可能在十字架上做-browser方式。

This is impossible to do in a cross-browser way.

我想到的唯一的跨浏览器方式(但并不简单)是上传文件ajax样式,渲染该图像(可能是隐藏)并使用 img.width img.height 获取其大小。

The only cross-browser way that comes to my mind (but is not simple) is to upload the file ajax style, render that image (could be hidden) and get its size with img.width and img.height.

希望这会有所帮助。干杯

Hope this helps. Cheers

这篇关于使用javascript获取文件标记中的图像高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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