
function DrawImage(ImgD,W,H){ 
  var flag=false; 
  var imgW=W;  
  var imgH=H;
        var image=new Image();   
        image.src=ImgD.src;   
        if(image.width>imgW){   
          flag=true;   
          if(image.width/image.height>=imgW/imgH){   
            if(image.width>imgW){       
            ImgD.width=imgW;   
            ImgD.height=(image.height*imgH)/image.width;   
            }else{   
            ImgD.width=image.width;       
            ImgD.height=image.height;   
            }   
            ImgD.alt=image.width+"กม"+image.height;   
            }   
          else{   
            if(image.height>imgH){       
            ImgD.height=imgH;   
            ImgD.width=(image.width*imgW)/image.height;             
            }else{   
            ImgD.width=image.width;       
            ImgD.height=image.height;   
            }   
            ImgD.alt=image.width+"กม"+image.height;   
            }   
          }   
  }     