Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > asp技巧

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

来源:中文源码网    浏览:150 次    日期:2024-05-18 16:31:55
【下载文档:  asp固定比例裁剪缩略图的方法.txt 】


ASP固定比例裁剪缩略图的方法
一般生成缩略图的方法有两种:
第一种:缩放成固定大小的小图片
第二种:缩放成等比例的小图片
第一种方法的缺点是,会使图片变形,例如一个身材苗条的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固定比例裁剪缩略图的实现方法,希望对大家的学习有所帮助。

相关内容