在asp中实现自动缩放图片(推荐)
2007-01-05 08:40
441 查看
自动实现图片的缩放js代码:
function scalePhoto(imgId,width,height){
var img = document.getElementById(imgId);
if(img != null){
var imgWidth = img.width;
var imgHeight = img.height;
if(imgWidth>width&&imgHeight>height){
//both image's width and height are larger than required one
var widthRate = imgWidth/width;
var heightRate = imgHeight/height;
if(widthRate>heightRate){
//use width to retrieve the image
img.width=width;
img.height=imgHeight*(width/imgWidth);
}else{
img.height=height;
img.width=imgWidth*(height/imgHeight);
}
}
else if(imgWidth>width){
//the image width lg than the required width
img.width=width;
img.height=imgHeight*(width/imgWidth);
}
else if(imgHeight>height){
//the image height lg than the required
img.height=height;
img.width=imgWidth*(height/imgHeight);
}
}
}
将以上代码复制后生成一个js文件。
在需要调用的asp文件中加入:
<SCRIPT src="includes/image.js" type=text/javascript></SCRIPT>
主要需要注意包含文件的路径。
然后在需要进行图象文件缩放的地方进行相应更改即可,其参考代码如下,红色部分即为修改部分。
<img src=\'#\'" " width="92" height="109" border=0 onload=scaleDefaultPhoto(<%=format_topphoto(rs3("Photo_top"))%>,100,133)>
function scalePhoto(imgId,width,height){
var img = document.getElementById(imgId);
if(img != null){
var imgWidth = img.width;
var imgHeight = img.height;
if(imgWidth>width&&imgHeight>height){
//both image's width and height are larger than required one
var widthRate = imgWidth/width;
var heightRate = imgHeight/height;
if(widthRate>heightRate){
//use width to retrieve the image
img.width=width;
img.height=imgHeight*(width/imgWidth);
}else{
img.height=height;
img.width=imgWidth*(height/imgHeight);
}
}
else if(imgWidth>width){
//the image width lg than the required width
img.width=width;
img.height=imgHeight*(width/imgWidth);
}
else if(imgHeight>height){
//the image height lg than the required
img.height=height;
img.width=imgWidth*(height/imgHeight);
}
}
}
将以上代码复制后生成一个js文件。
在需要调用的asp文件中加入:
<SCRIPT src="includes/image.js" type=text/javascript></SCRIPT>
主要需要注意包含文件的路径。
然后在需要进行图象文件缩放的地方进行相应更改即可,其参考代码如下,红色部分即为修改部分。
<img src=\'#\'" " width="92" height="109" border=0 onload=scaleDefaultPhoto(<%=format_topphoto(rs3("Photo_top"))%>,100,133)>
相关文章推荐
- 如何实现ASP上传图片自动生成缩略图
- Android 实现图片自动缩放自定义控件
- Asp.Net 自定义控件实现图片的上传,浏览,Delete功能 推荐
- 利用Javascript 与 VBscript 在asp中实现图片自动切换
- asp正则html的图片,对图自动缩放大小
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载续][重点推荐控件]
- Android 实现图片的自动缩放,适应分辨率不同的手机
- asp.net用鼠标滚轮实现图片缩放实现方法
- 使用Tengine+Lua+GraphicsMagick实现图片自动裁剪缩放
- 图片置顶\居中\不同手机屏幕自动缩放的实现
- js实现固定显示区域内自动缩放图片的方法
- Javascript + Asp.net 让图片自动成比例缩放
- 如何实现ASP上传图片自动生成缩略图
- 在C#中实现图片缩放(含asp.net用鼠标滚轮实现图片缩放)
- 基于JQuery实现的图片自动进行缩放和裁剪处理
- jquery实现根据浏览器窗口大小自动缩放图片的方法
- jquery实现根据浏览器窗口大小自动缩放图片的方法
- ASP.NET前台页面实现图片自动播放
- Tengine + Lua + GraphicsMagick 实现图片自动裁剪/缩放 - 腾勇的个人页面 - 开源中国社区
- Qt5:随窗口大小变化背景图片自动缩放的实现