function f(ID){return document.getElementById(ID)}
// JavaScript Document
var flag=false; 

function DrawImage(ImgD,w,h){ 

var image=new Image(); 

var iwidth = w;  //定义允许图片宽度 

var iheight = h;  //定义允许图片高度 

image.src=ImgD.src; 

if(image.width>0 && image.height>0){ 

flag=true; 

if(image.width/image.height>= iwidth/iheight){ 

  if(image.width>iwidth){   

   ImgD.style.width=iwidth+"px";

   ImgD.style.height=(image.height*iwidth)/image.width+"px";

   var pgh=iheight - (image.height*iwidth)/image.width; 
   setHeight(ImgD,pgh);
   }else{ 

   ImgD.style.width=image.width+"px";

   ImgD.style.height=image.height+"px";
   
   var pgw=iwidth - image.width;
   var pgh=iheight - image.height;
   setWidth(ImgD,pgw);
   setHeight(ImgD,pgh);
   } 

  // ImgD.alt=image.width+"×"+image.height; 

   } 

else{ 

  if(image.height>iheight){   

   ImgD.style.height=iheight+"px";

   ImgD.style.width=(image.width*iheight)/image.height+"px";

   var pgw=iwidth - (image.width*iheight)/image.height;
   setWidth(ImgD,pgw);
   }else{ 

   ImgD.style.width=image.width+"px";
   ImgD.style.height=image.height+"px";
   var pgw=iwidth - image.width;
   var pgh=iheight - image.height;
   setWidth(ImgD,pgw);
   setHeight(ImgD,pgh);
   } 

   //ImgD.alt=image.width+"×"+image.height; 

   } 

} 

} 

