图片加载并按比例缩小到合适大小(非原创)

//图片加载并按比例缩小到合适大小
//
<img src=""  width="80" onload="DownImage(this,80,0,0);">
function DownImageWidth(ImgD,MaxWidth,alignX,alignY)
{
    alignX
=alignX||1;
    alignY
=alignY||1;
   
var image=new Image();
    image.src
=ImgD.src;
   
if(image.width>0 && image.height>0)
    {
       
var rate = MaxWidth/image.width;
        var wid=0;
       
var hid=0;
       
if(rate <= 1)
        {
            wid
=ImgD.width=image.width*rate;
            hid
=ImgD.height=image.height*rate;
        }
       
else
        {
            wid
=ImgD.width=image.width;
            hid
=ImgD.height=image.height;
        }
    }
}
posted @ 2011-04-22 14:13  黑色街角  阅读(302)  评论(0编辑  收藏  举报