js等比例缩放图像

function DrawImage(ImgD,iwidth,iheight){
	var image=new Image();
	if(!iwidth)iwidth=90;
	if(!iheight)iheight=90;
	image.src=ImgD.src;
	if(image.width>0&&image.height>0){
		var flag=true;
		if(image.width/image.height>=iwidth/iheight){
			if(image.width>iwidth){
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}else{
			if(image.height>iheight){
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
	}
}

来源 http://t.auto.sina.com.cn/shanghaichezhan/2011weibounion/



你可能感兴趣的:(javascript)