当前位置: 移动技术网 > IT编程>开发语言>Asp > ASP固定比例裁剪缩略图的方法

ASP固定比例裁剪缩略图的方法

2017年12月01日  | 移动技术网IT编程  | 我要评论

一般生成缩略图的方法有两种:

第一种:缩放成固定大小的小图片

第二种:缩放成等比例的小图片

第一种方法的缺点是,会使图片变形,例如一个身材苗条的mm变成一个胖mm

第二种方法的缺点是,如果图片是放在一个表格中显示,并且图片宽高比和这个表格不同,就不能充满整个表格,留下空隙,不好看

这里介绍的方法是“固定比例裁剪”,使用aspjpeg组件,也就是说,生成的缩略图宽高比是固定的,但是不会变形。如果原图的宽高比大于设定的宽高比,就会自动剪掉左右两旁多余的图;如果原图的宽高比小于设定的宽高比,就会自动剪掉上下的多余的图。

function makepic(sourcpic,newwidth,newheight,destpic) 
on error resume next 
makepic=false 
set jpeg = server.createobject(“persits.jpeg”) 
if err then 
response.write (“错误:空间没安装aspjpeg组件”) 
response.end 
end if 
jpeg.quality = 100 
jpeg.open sourcpic 
jpeg.preserveaspectratio = true ‘等比缩放 
if jpeg.originalwidth/jpeg.originalheight > newwidth/newheight then'太扁了,要剪掉左右部分 
jpeg.height = newheight 
jpeg.crop cint((jpeg.width – newwidth)/2),0,cint((jpeg.width – newwidth)/2)+newwidth,newheight 
else ‘太高了,要剪掉上下部分 
jpeg.width = newwidth 
jpeg.crop 0,cint((jpeg.height – newheight)/2),newwidth,cint((jpeg.height – newheight)/2)+newheight 
end if 
jpeg.save destpic 
if err.number=0 then makepic=true 
jpeg.close 
set jpeg=nothing 
end function

以上就是介绍asp使用aspjpeg固定比例裁剪缩略图的实现方法,希望对大家的学习有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网