好久没有发文章,贴一段代码出来晒晒!一段aspjpeg组件生成缩略图的代码,有4种生成方式,建议用最后一种,生成的缩略图最清晰而且不会拉伸、变形!做图片生成最好不过!
- // 缩略图生成函数 Code By Shaoyun
- // 参数:生成文件全路径、保存文件全路径、限定宽度、限定高度、生成方式
- // 调用示例
- // filepath="images/"
- // savepath="thumbs/"
- // srcfile="4.jpg"
- // destfile="s10.jpg"
- // srcfile=Server.MapPath(filepath & srcfile)
- // destfile=Server.MapPath(savepath & destfile)
- // call makethumb(srcfile,destfile,200,120,3)
- function MakeThumb(fileName,saveName,limitW,limitH,nType)
- if not(limitW>0 or limitH>0) then exit function
- Dim ojpg,oh,ow
- Set ojpg = Server.CreateObject("Persits.Jpeg")
- ojpg.open fileName
- oh = ojpg.OriginalHeight
- ow = ojpg.OriginalWidth
- select case nType
- case 0
- Rem 限定宽高
- if limitW>0 and limitH>0 then
- ojpg.width=limitW
- ojpg.height=limitH
- end if
- case 1
- Rem 只限定宽度,高度按比例
- if limitW>0 then
- ojpg.width=limitW
- ojpg.height=oh/ow*limitW
- end if
- case 2
- Rem 只限定高度,宽度按比例
- if limitH>0 then
- ojpg.height=limitH
- ojpg.width=ow/oh*limitH
- end if
- case 3
- Rem 按限定的宽高比裁切
- if limitW>0 and limitH>0 then
- Dim lheight:lheight=oh*limitW/ow
- If lheight
Then - ojpg.Height = limitH
- ojpg.Width = ow*ojpg.Height/oh
- Else
- ojpg.width = limitW
- ojpg.Height = oh*ojpg.width/ow
- End if
- ojpg.Crop 0, 0,limitW,limitH
- End If
- case else
- exit function
- end select
- ojpg.Quality = 90
- ojpg.save saveName
- Set ojpg = nothing
- end function