知识库

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

来源: 本站    类别: 知识库    日期: 2016/3/1

 

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

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

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

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

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

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

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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固定比例裁剪缩略图的实现方法,希望对大家的学习有所帮助。


相关文章


Copyright © 2004 - 2024 CNHWW Inc. All Rights Reserved
石家庄市征红网络科技有限公司版权所有 邮政编码:050051
服务电话:0311-85315152 13931185013 在线客服QQ:81447932 / 81447933 邮箱: cnhww@163.com