﻿// JScript 文件
//图片按比例放大缩小
 var flag=false; 
    function DrawImage(ImgD,nw,nh)
    {   //ImgD为图片的ID, nw为要设置的宽度，nh为要设置的长度
        var image=new Image();   
        image.src=ImgD.src;   
        if(image.width>0 && image.height>0)
        {   
           flag=true;   
          if(image.width/image.height>= nw/nh)
          {   
            if(image.width>nw)
            {       
                ImgD.width=nw;   
                ImgD.height=(image.height*nw)/image.width;   
            }
            else
            {   
                ImgD.width=image.width;       
                ImgD.height=image.height;   
            }   
          }   
          else
          {   
            if(image.height>nh)
            {       
                ImgD.height=nh;   
                ImgD.width=(image.width*nh)/image.height;             
            }
            else
            {   
                ImgD.width=image.width;       
                ImgD.height=image.height;   
            }   
           }   
        }
     }     
