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