限制网页图片尺寸
2012-03-29 12:45
330 查看
<script language=JavaScript>
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 140/180){
if(image.width>140){
ImgD.width=140;
ImgD.height=(image.height*140)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
/*ImgD.alt=image.width+"×"+image.height;*/
}
else{
if(image.height>180){
ImgD.height=180;
ImgD.width=(image.width*180)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
/*ImgD.alt=image.width+"×"+image.height;*/
}
}
/*else{
ImgD.src="";
ImgD.alt=""
}*/
}
</script>
把以上这段代码加在<head></head>之间
然后在图片显示的时候,用这种方式:
<img src='xxx.gif' border=0 onload='javascript:DrawImage(this);'> (其中xxx.gif是你要显示的图片)
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 140/180){
if(image.width>140){
ImgD.width=140;
ImgD.height=(image.height*140)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
/*ImgD.alt=image.width+"×"+image.height;*/
}
else{
if(image.height>180){
ImgD.height=180;
ImgD.width=(image.width*180)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
/*ImgD.alt=image.width+"×"+image.height;*/
}
}
/*else{
ImgD.src="";
ImgD.alt=""
}*/
}
</script>
把以上这段代码加在<head></head>之间
然后在图片显示的时候,用这种方式:
<img src='xxx.gif' border=0 onload='javascript:DrawImage(this);'> (其中xxx.gif是你要显示的图片)
相关文章推荐
- 限制网页图片尺寸
- 如何实现限制网页图片尺寸(客户端)?
- JS限制图片最大尺寸
- js限制上传图片的格式和尺寸
- css样式限制、防止表格被连续英文字母拉长 及 控制大图片的网页宽度
- ASP.NET MVC在服务端把异步上传的图片裁剪成不同尺寸分别保存,并设置上传目录的尺寸限制
- 手机网页图片自适应大小 background-size css 图片全屏 背景尺寸设置
- 让背景图片居中,在网页固定尺寸内…
- 发布文章“下载远程图片”,缩略图片在限制尺寸之内(dede 5.5)
- angular-file-upload封装为指令+图片尺寸限制
- 调用七牛SDK,在上传之前限制图片尺寸大小
- 发布文章“下载远程图片”,缩略图片在限制尺寸之内
- 巧用isee“压缩”限制图片的文件大小及其尺寸
- 前台JS限制上传图片质量大小和尺寸
- 手机端网页设计尺寸,手机端网页设计图片尺寸
- 前台js限制上传图片质量大小和尺寸
- JS 使用 Android + IOS 相册 + 相机 进行自定义头像 + 限制裁剪后图片尺寸 + base64 string 与 图片互相转换
- JS获取网页图片的实际尺寸
- css样式限制、防止表格被连续英文字母拉长 及 控制大图片的网页宽度
- 手机网页图片自适应大小 background-size css 图片全屏 背景尺寸设置