function fitImage(img, x, y) {
	var actual = new Image();
	actual.onload = function() {
		if (actual.width / actual.height > x / y) {
			// 横長画像
			img.style.width = x + "px";
			img.style.height = actual.height * x / actual.width + "px";
		} else {
			// 縦長画像
			img.style.width = actual.width * y / actual.height + "px";
			img.style.height = y + "px";
		}
	}
	actual.src = img.src;
}

