Scale Down Image Using JavaScript

由 joelhy 于 周五, 09/14/2007 - 17:54 提交。

/**
 * Scaling image down to maxWidth X maxHeight
 */
function scaleDownImage(image, maxWidth, maxHeight)
{
	if ((image.width/image.height) > (maxWidth/maxHeight)) {
		if (image.width > maxWidth) {
			image.resized = true;
			image.width  = maxWidth;
		}
	} else {
		if (image.height > maxHeight) {
			image.resized = true;
			image.height = maxHeight;
		}
	}
}

回复

此内容将保密,不会被其他人看见。
  • 网页地址和电子邮件地址将会被自动转换为链接。
  • 允许的 HTML 标签: <img> <p> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <coolcode>
  • You can use coolfilter tags in the text, to include code and media

更多格式化选项信息