var flag=false; 
function DrawImage(ImgD,img_w,img_h){ 
var image=new Image(); 
image.src=ImgD.src; 
if(image.width>0 && image.height>0){ 
flag=true; 
if(image.width/image.height>= img_w/img_h){ 
if(image.width>img_w){ 
ImgD.width=img_w; 
ImgD.height=(image.height*img_w)/image.width; 
}else{ 
ImgD.width=image.width; 
ImgD.height=image.height; 
} 
} 
else{ 
if(image.height>img_h){ 
ImgD.height=img_h; 
ImgD.width=(image.width*img_h)/image.height; 
}else{ 
ImgD.width=image.width; 
ImgD.height=image.height; 
} 
} 
} 
} 
