356 字2 分钟
BBSXP的 AspJpeg 水印函数
今天装了一个 asp 的 bbs,很经典的 BBSXP 程序,最后一次玩还是高三的时候,如今大学都毕业了….
看了附件上传部分的代码,比我的 WindsPhoto 处理图片水印强很多,精华代码在这个函数,很有参考价值,贴出来学习一下。
Function JpegPersitsif SiteConfig("WatermarkType")=0 thenJpeg.Canvas.Font.Color = Replace(SiteConfig("WatermarkFontColor"),"#","&h") '颜色Jpeg.Canvas.Font.Family = SiteConfig("WatermarkFontFamily") '字体Jpeg.Canvas.Font.size = SiteConfig("WatermarkFontSize") '大小Jpeg.Canvas.Font.Bold = CBool(SiteConfig("WatermarkFontIsBold")) '是否加粗'Jpeg.Canvas.Font.ShadowXoffset = 10 '水印文字阴影向右偏移的像素值,输入负值则向左偏移'Jpeg.Canvas.Font.ShadowYoffset = 10 '水印文字阴影向下偏移的像素值,输入负值则向右偏移Title = SiteConfig("WatermarkText")TitleWidth = Jpeg.Canvas.GetTextExtent(Title)if Jpeg.Width<TitleWidth then exit function '图片比水印文字小,则不加水印select case SiteConfig("WatermarkWidthPosition")case "left"PositionWidth=10case "center"PositionWidth=(Jpeg.Width - TitleWidth) / 2case "right"PositionWidth= Jpeg.Width - TitleWidth - 10end selectJpeg.Canvas.Print PositionWidth, 10, Title'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''elseif SiteConfig("WatermarkType")=1 thenSet Jpeg2 = Server.CreateObject("Persits.Jpeg")Jpeg2.Open Server.MapPath(SiteConfig("WatermarkImage"))Jpeg2Width=Jpeg2.OriginalWidthJpeg2Height=Jpeg2.OriginalHeightif Jpeg.Width<Jpeg2Width or Jpeg.Height<Jpeg2Height*2 then exit function '图片比水印图片小,则不加水印select case SiteConfig("WatermarkWidthPosition")case "left"PositionWidth=10case "center"PositionWidth=(Jpeg.Width - Jpeg2Width) / 2case "right"PositionWidth= Jpeg.Width - Jpeg2Width - 10end selectselect case SiteConfig("WatermarkHeightPosition")case "top"PositionHeight=10case "center"PositionHeight=(Jpeg.Height - Jpeg2Height) / 2case "bottom"PositionHeight= Jpeg.Height - Jpeg2Height - 10end selectJpeg.Canvas.DrawImage PositionWidth, PositionHeight, Jpeg2, 1, &HFFFFFF '透明度, 透明颜色end ifEnd Function