ASP wsImage组件添加水印的实用代码(6)
do:p1=binVal(aso.Read(1)):loop while p1<255 and not aso.EOS
loop while true
aso.Read(3)
ret(0)="JPG"
ret(2)=binval2(aso.Read(2))
ret(1)=binval2(aso.Read(2))
case else:
if left(Bin2Str(bFlag),2)="BM" then
aso.Read(15)
ret(0)="BMP"
ret(1)=binval(aso.Read(4))
ret(2)=binval(aso.Read(4))
else
ret(0)=""
end if
end select
ret(3)="width=""" & ret(1) &""" height=""" & ret(2) &""""
getimagesize=ret
End Function
End Class
SavefullPath="326151745wldn.jpg" '图片路径赋值 或 图片路径变量赋值
'取得图片的宽度
Set qswh = new qswhImg
arr = qswh.getImageSize(Server.Mappath(SavefullPath))
Set qswh = Nothing
str_ImgWidth=arr(1)
str_ImgHeight=arr(2)
If Int(str_ImgWidth) > 600 Then
str_ImgWidth = 600
Else
str_ImgWidth = str_ImgWidth
End If
'加水印
If Int(str_ImgWidth) > 300 And Int(str_ImgHeight) > 100 Then
LocalFile=Server.MapPath(SavefullPath)
TargetFile=Server.MapPath(SavefullPath)
Dim Jpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")
If -2147221005=Err then
Response.Write("<script language='javascript'>alert('没有这个组件,请安装!');history.back();</script>") '检查是否安装AspJpeg组件
Response.End()
End If
Jpeg.Open (LocalFile) '打开图片
If err.number then
Response.Write("<script language='javascript'>alert('打开图片失败,请检查路径!');history.back();</script>")
Response.End()
End if
Dim aa
aa=Jpeg.Binary '将原始数据赋给aa
'=========加文字水印=================
Jpeg.Canvas.Font.Color = &Hfffffff '水印文字颜色
Jpeg.Canvas.Font.Family = Arial '字体
Jpeg.Canvas.Font.Bold = True '是否加粗
Jpeg.Canvas.Font.Size = 20 '字体大小
Jpeg.Canvas.Font.ShadowColor = &H000000 '阴影色彩
Jpeg.Canvas.Font.ShadowYOffset = 1
Jpeg.Canvas.Font.ShadowXOffset = 1
Jpeg.Canvas.Brush.Solid = True
Jpeg.Canvas.Font.Quality = 10 ' '输出质量
Jpeg.Canvas.PrintText Jpeg.OriginalWidth/2-40,Jpeg.OriginalHeight/2-10,"网站建设" '水印位置及文字
bb=Jpeg.Binary '将文字水印处理后的值赋给bb,这时,文字水印没有不透明度
'============调整文字透明度================
Set MyJpeg = Server.CreateObject("Persits.Jpeg")
MyJpeg.OpenBinary aa
Set Logo = Server.CreateObject("Persits.Jpeg")
Logo.OpenBinary bb
MyJpeg.DrawImage 0,0, Logo, 0.5 '0.3是透明度
cc=MyJpeg.Binary '将最终结果赋值给cc,这时也可以生成目标图片了
Response.BinaryWrite cc '将二进输出给浏览器
MyJpeg.Save (TargetFile)
set aa = nothing
set bb = nothing
set cc = nothing
Jpeg.Close
MyJpeg.Close
Logo.Close
End If
'加水印
%>