图片按比例缩放函数
2007-09-07 11:34
399 查看
图片按比例缩放函数:
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 150; //定义允许图片宽度
var iheight = 100; //定义允许图片高度
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//调用:<img src="图片" onload="javascript:DrawImage(this)">
//-->
</script>
示例如下:
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 150; //定义允许图片宽度
var iheight = 100; //定义允许图片高度
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//调用:<img src="图片" onload="javascript:DrawImage(this)">
//-->
</script>
<img src="http://www.webjx.com/img/200406301.jpg" onload="javascript:DrawImage(this)">
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 150; //定义允许图片宽度
var iheight = 100; //定义允许图片高度
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//调用:<img src="图片" onload="javascript:DrawImage(this)">
//-->
</script>
示例如下:
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 150; //定义允许图片宽度
var iheight = 100; //定义允许图片高度
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//调用:<img src="图片" onload="javascript:DrawImage(this)">
//-->
</script>
<img src="http://www.webjx.com/img/200406301.jpg" onload="javascript:DrawImage(this)">
相关文章推荐
- jquery获取select中的option的text值|| PHP图片缩放函数:实现等比例不失真缩放
- 等比例缩放图片的函数
- PHP图片等比例缩放生成缩略图函数分享
- JavaScript,等比例缩放图片的函数
- JavaScript,等比例缩放图片的函数,很好用。
- 一个对上传图片进行处理的函数(等比例缩放) --koma
- 一个非常好用的图片等比例缩放到指定最大高宽的函数
- 图片按比例缩放函数
- PHP图片缩放函数:实现等比例不失真缩放
- JavaScript,等比例缩放图片的函数,很好用。
- PHP自定义图片缩放函数实现等比例不失真缩放的方法
- JavaScript,等比例缩放图片的函数
- PHP图片缩放函数:实现等比例不失真缩放
- PHP图片等比例缩放生成缩略图函数分享
- 一个可以使得上传的图片大小按照指定的宽度,高度自动按比例进行缩放的函数(C#)
- 图片按比例缩放函数
- 通过loadPicture函数来获取图片的高与宽和缩放,解决客户端再按比例缩小
- JavaScript,等比例缩放图片的函数,很好用。
- PHP自定义图片缩放函数实现等比例不失真缩放的方法
- JavaScript,等比例缩放图片的函数,很好用。