用JPEG组件生成缩略图
原文:http://bbs.blueidea.com/thread-2863133-1-1.html
TargetFile:目标地址
strWidth:最大宽度
strHeight:最大高度
'****************************************************
'函数名:getThumbnail
'作者:www.goimage.cn
'作 用:真正按比例生成缩略图
'****************************************************
Function getThumbnail(LocalFile, TargetFile, strWidth, strHeight)
Dim Jpeg
Set Jpeg = Server.Createobject("Persits.Jpeg")
Jpeg.open server.MapPath(LocalFile)
Dim OriginalWidth, OriginalHeight '原图片宽度、高度
Dim BuildWidth, BuildHeight '缩略图宽度、高度
Dim ii, iii
Dim iiii, iiiii
OriginalWidth = Jpeg.Width
OriginalHeight = Jpeg.Height
ii = OriginalWidth / OriginalHeight
iii = OriginalHeight / OriginalWidth
iiii = 0
iiiii = 0
If OriginalWidth > strWidth Then
iiii = OriginalWidth / strWidth
Else
BuildWidth = OriginalWidth
End If
If OriginalHeight > strHeight Then
iiiii = OriginalHeight / strHeight
Else
BuildHeight = OriginalHeight
End If
If iiii <> 0 Or iiiii <> 0 Then
If iiii > iiiii Then
BuildWidth = strWidth
BuildHeight = strWidth * iii
Else
BuildWidth = strHeight * ii
BuildHeight = strHeight
End If
End If
'指定宽度和高度生成
Jpeg.Width = BuildWidth
Jpeg.Height = BuildHeight
Jpeg.Save Server.MapPath(TargetFile) '//生成缩略图位置及名称
'注销实例
Set Jpeg = Nothing
End Function
LocalFile:源图TargetFile:目标地址
strWidth:最大宽度
strHeight:最大高度