JavaScript获取图片尺寸
2012-02-21 11:20
309 查看
方法一:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>分享javascript-sharejs.com</title>
</head>
<body>
<script>
var img=null;
function s()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=inp.value;
}
function oe()
{
alert("cant load img");
}
function orsc()
{
if(img.readyState!="complete")return false;
alert("高:"+img.offsetHeight+"\n宽:"+img.offsetWidth);
}
</script>
<input type="file" Name="file" id="inp" value="默认值"><br><input onclick="s()" type="button" value="点我一下给出要上传图片的大小及长、宽" name="button">
<br><br>
</body>
</html>
方法二:
<html>
<head>
<script >
<!--
function QFord_getImageSize(FilePath)
{
var imgSize={
width:0,
height:0
};
image=new Image();
image.src=FilePath;
imgSize.width =image .width;
imgSize .height=image .height;
return imgSize;
}
// -->
</script>
</head>
<body bgcolor="#ffffff">
JS获取图片尺寸函数测试:</br>
<img src="test.jpg" mce_src="test.jpg" />
<script type="text/javascript">
<!--
var a=QFord_getImageSize("test.jpg");
alert('宽:'+a.width +' 高:'+a.height);
// -->
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>分享javascript-sharejs.com</title>
</head>
<body>
<script>
var img=null;
function s()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=inp.value;
}
function oe()
{
alert("cant load img");
}
function orsc()
{
if(img.readyState!="complete")return false;
alert("高:"+img.offsetHeight+"\n宽:"+img.offsetWidth);
}
</script>
<input type="file" Name="file" id="inp" value="默认值"><br><input onclick="s()" type="button" value="点我一下给出要上传图片的大小及长、宽" name="button">
<br><br>
</body>
</html>
方法二:
<html>
<head>
<script >
<!--
function QFord_getImageSize(FilePath)
{
var imgSize={
width:0,
height:0
};
image=new Image();
image.src=FilePath;
imgSize.width =image .width;
imgSize .height=image .height;
return imgSize;
}
// -->
</script>
</head>
<body bgcolor="#ffffff">
JS获取图片尺寸函数测试:</br>
<img src="test.jpg" mce_src="test.jpg" />
<script type="text/javascript">
<!--
var a=QFord_getImageSize("test.jpg");
alert('宽:'+a.width +' 高:'+a.height);
// -->
</script>
</body>
</html>
相关文章推荐
- 如何用JavaScript在浏览器端获取图片的原始尺寸大小?
- JavaScript获取图片的原始尺寸
- javascript获取图片大小和尺寸
- javascript加载图片获取图片尺寸信息方法
- JavaScript获取页面图片原始尺寸
- JavaScript获取图片的原始尺寸
- javascript 获取图片尺寸及放大图片
- JavaScript获取图片的原始尺寸
- 如何用JavaScript在浏览器端获取图片的原始尺寸大小?
- JavaScript获取图片的原始尺寸以宽度为例
- javascript图片预加载快速获取图片尺寸
- JavaScript获取图片的原始尺寸
- javascript 获取图片原始尺寸
- 比onload更快获取图片尺寸的javascript图片预加载技术
- javascript图片预加载快速获取图片尺寸
- JavaScript怎么判断图片是否加载完成以便获取其尺寸
- 如何用JavaScript获取图片的真实尺寸大小
- JavaScript获取图片的原始尺寸
- 使用JavaScript获取图片的真实尺寸大小
- JavaScript简单获取页面图片原始尺寸的方法