生成的缩略图宽高比是固定的,但是不会变形。如果原图的宽高比大于设定的宽高比,就会自动剪掉左右两旁多余的图;如果原图的宽高比小于设定的宽高比,就会自动剪掉上下的多余的图,必然是纯js,谢谢!
再比如
一张图片为700*900裁剪后的缩略图为200*100如可实现???
再比如
一张图片为700*900裁剪后的缩略图为200*100如可实现???
解决方案 »
- 百度地图的js怎么传递参数
- insertRow() 设置事件 页面无效果 求助!
- 请问如何根据输入的月份知道次月共有几周?
- 表单循环验证
- 动态设置href属性为javascript 错误
- 对于梅花雪的树,想增加Checkbox功能,以及动态增加、修改、删除结点功能,如何实现?请教!
- 关于获取控件值的问题?
- 正则表达式中的replace?
- <------------关于marquee的问题,请高手指教---------->
- java web程序jsp页面一直在循环执行文档就绪函数!
- 如何将以下内容分别向,两个为NAV1和NAV2的ID输出(新手问题)
- 如何使网页被浏览的时候自动加载一种特殊字体(注:是静态网页)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
function Zoom(){
var div = $("container");
var bigImg = $("bigImg");
var width = parseInt(($("Width").value || 160), 10);
var height = parseInt(($("Height").value || 90), 10);
var oldWidth = bigImg.width;
var oldHeight = bigImg.height;
var scale = Math.max(width / oldWidth, height / oldHeight);
var newWidth = oldWidth * scale;
var newHeight = oldHeight * scale;
div.style.width = width + "px";
div.style.height = height + "px";
div.style.overflow = "hidden"; var smallImg = $("smallImg");
smallImg.style.display = "block";
smallImg.src = bigImg.src;
smallImg.style.width = newWidth + "px";
smallImg.style.height = newHeight + "px";
smallImg.style.marginLeft = (width - newWidth) / 2 + "px";
smallImg.style.marginTop = (height - newHeight) / 2 + "px";
}
</script>
</head><body>
<div id="container"><img id="smallImg" style="display:none" /></div><br />
缩略图大小:<input type="text" name="Width" id="Width" size="4" /> - <input type="text" name="Height" id="Height" size="4" />
<input type="button" value="裁剪" onclick="Zoom()" />
<img id="bigImg" src="http://hiphotos.baidu.com/中国旅游名县/pic/item/56d16e00e83803a6e850cdb2.jpg" width="800" height="600" border="0" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function Zoom(obj, width, height){
var scale = Math.max(width / obj.width, height / obj.height);
var newWidth = obj.width * scale;
var newHeight = obj.height * scale;
var div = obj.parentNode; obj.width = newWidth;
obj.height = newHeight;
div.style.width = width + "px";
div.style.height = height + "px";
div.style.overflow = "hidden";
obj.style.marginLeft = (width - newWidth) / 2 + "px";
obj.style.marginTop = (height - newHeight) / 2 + "px";
}
</script>
</head><body>
<div><img src="http://hiphotos.baidu.com/中国旅游名县/pic/item/56d16e00e83803a6e850cdb2.jpg" onload="Zoom(this, 500, 100)" border="0" /></div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function Zoom(obj, width, height){
var img = new Image();
img.src = obj.src;
var scale = Math.max(width / img.width, height / img.height);
var newWidth = img.width * scale;
var newHeight = img.height * scale;
var div = obj.parentNode; obj.width = newWidth;
obj.height = newHeight;
div.style.width = width + "px";
div.style.height = height + "px";
div.style.overflow = "hidden";
obj.style.marginLeft = (width - newWidth) / 2 + "px";
obj.style.marginTop = (height - newHeight) / 2 + "px";
}
</script>
</head><body>
<div><img src="http://hiphotos.baidu.com/中国旅游名县/pic/item/56d16e00e83803a6e850cdb2.jpg" width="400" height="300" onload="Zoom(this, 500, 100)" border="0" /></div>
</body>
</html>