function DrawImage(ImgD,iwidth,iheight){
	//调用过程 onload='DrawImage(this,200,400,"w","h")'
	//w，h是分别表示左右居中、垂直居中 有时候也可以不写
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
    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;
        }
        }
    else{
        if(image.height>iheight){  
        ImgD.height=iheight;
        ImgD.width=(image.width*iheight)/image.height;        
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        }
    }
	
	   //设置是否水平垂直居中
       //如果第三个参数之后有个“w”参数，左右居中
		if(arguments[3]=='w' || arguments[4]=='w'){
	       if(iwidth>ImgD.width && ImgD.width>0){
	       ImgD.style.marginLeft=(iwidth-ImgD.width)/2;
	   	   ImgD.style.marginRight=(iwidth-ImgD.width)/2;
		   }
		}
		//如果第三个参数之后有个“h”参数，上下居中
		if(arguments[3]=='h' || arguments[4]=='h'){
		   if(iheight>ImgD.height && ImgD.height>0){
		   ImgD.style.marginTop=(iheight-ImgD.height)/2;
		   ImgD.style.marginBottom=(iheight-ImgD.height)/2;
		   }
		}	
	
} 


