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

// 图片加载并按比例缩小到合适大小
//
<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;
        }
    }
}

你可能感兴趣的:(图片加载)