JavaScript图片保持纵横比缩放代码。
作者:cmscn 日期:2007-09-14
function DrawImage(ImgD,maxSize)
{
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0)
{
if(image.width/image.height>=1)
{
if(image.width>maxSize)
{
ImgD.width=maxSize;
ImgD.height=(image.height*maxSize)/image.width;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else
{
if(image.height>maxSize)
{
ImgD.height=maxSize;
ImgD.width=(image.width*maxSize)/image.height;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
评论: 0 | 引用: 0 | 查看次数: 665
发表评论