﻿
//图片按比例缩放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
    //参数(图片,允许的宽度,允许的高度)
	var mwidth = ImgD.width;
	var mheight = ImgD.height;
	ImgD.width=iwidth;  
    ImgD.height=iheight;
	if(mwidth>0 && mheight>0){
	    if(mwidth/mheight>= iwidth/iheight){
        if(mwidth>iwidth){  
        ImgD.width=iwidth;
        ImgD.height=(mheight*iwidth)/mwidth;
        }else{
        ImgD.width=mwidth;  
        ImgD.height=mheight;
        }
        }
    else{
        if(mheight>iheight){  
        ImgD.height=iheight;
        ImgD.width=(mwidth*iheight)/mheight;        
        }else{
        ImgD.width=mwidth;  
        ImgD.height=mheight;
        }
        }
    }
} 
//<!-- 
//调用：<img src="图片" onload="javascript:DrawImage(this,100,100)">
//-->

