为什么我上传到网站的图片(JPG格式)会变形呢?
1个回答
展开全部
没按比例缩放
<script language= "JavaScript ">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 120; //定义允许图片宽度
var iheight = 90; //定义允许图片高度
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;
}
}
}
//-->
</script>
<script language= "JavaScript ">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 120; //定义允许图片宽度
var iheight = 90; //定义允许图片高度
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;
}
}
}
//-->
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询