---
title: "缩放图片JS"
author: "shen211"
date: "2010-08-25T09:26:17Z"
tags: []
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2010-08-25T09:26:17Z"
id: 746529
url: "https://shen211.iteye.com/blog/746529"
---

/**
*
*img 为<img/>对象 
*/
function drawImg(img,boxWidth, boxHeight) {
	var imgWidth = img.width;
	var imgHeight = img.height;
	if ((boxWidth / boxHeight) >= (imgWidth / imgHeight)) {
		img.width = ((boxHeight * imgWidth) / imgHeight);
		img.height = (boxHeight);
	} else {
		img.width = (boxWidth);
		img.height = ((boxWidth * imgHeight) / imgWidth);
	}
}