AspJpeg组件:介绍、注册、高级使用方法(3)
时间:2010-01-25 12:42:00
11、如何用AspJpeg组件创建安全码?
创建安全码原理上和创建水印差不多。
<%
Function make_randomize(max_len, w_n) 'max_len 生成长度,w_n:0 可能包含字母,1:只为数字
Randomize
For intcounter = 1 To max_len
whatnext = Int((1 -0 + 1) * Rnd + w_n)
If whatnext = 0 Then
upper = 122
lower = 97
Else
upper = 57
lower = 48
End If
strnewpass = strnewpass & Chr(Int((upper - lower + 1) * Rnd) + lower)
Next
make_randomize = strnewpass
End Function
'生成安全码的图片。
random_num = make_randomize(4, 1) ''生成4位数字的安全码
session("random_num") = random_num '为么调用session,没有session的安全码是完全没有意义的。呵呵 .
Set Jpeg = Server.CreateObject("Persits.Jpeg") '调用组件
Jpeg.Open Server.MapPath("t.jpg") '打开准备的图片
Jpeg.Canvas.Font.Color = &HFFFFFF
Jpeg.Canvas.Font.Family = "Arial Black"
Jpeg.Canvas.Font.Bold = false
Jpeg.Canvas.PrintText 0, -2, random_num
jpeg.save Server.MapPath("tt.jpg") '保存
%>
12、如何让AspJpeg组件支援数据库?
图片存进数据库只能以二进制数据保存,这里即利用AspJpeg的Binary方法,下面以两个AspJpeg用户手册上的代码为例,具体请参考AspJpeg用户手册:
Opening Images from Memory
<%' Using ADO, open database with an image blob
strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("../db/aspjpeg.mdb")
Set rs = Server.CreateObject("adodb.recordset")
SQL = "select image_blob from images2 where id = " & Request("id")
rs.Open SQL, strConnect, 1, 3
Set Jpeg = Server.CreateObject("Persits.Jpeg")
' Open image directly from recordset
Jpeg.OpenBinary rs("image_blob").Value
' Resize
jpeg.Width = Request("Width")
' Set new height, preserve original aspect ratio
jpeg.Height = jpeg.OriginalHeight * jpeg.Width / jpeg.OriginalWidth
Jpeg.SendBinary
rs.Close
%>
Output to Memory
<%
...
Set rs = Server.CreateObject("adodb.recordset")
rs.Open "images", strConnect, 1, 3
rs.AddNew
rs("image_blob").Value = Jpeg.Binary
rs.Update
...
%>
一个生成文字水印的过程
<%
'call jpegclass(图片相对路径, 文字字体大小, 文字字体, 是否加粗, 距顶部距离, 距左边距离, 水印内容)
Sub jpegclass(J_imgurl, J_fontsize, J_family, J_isbold, J_top, J_Left, J_Content) '调用过程名
If Len(J_imgurl) = 0 or Len(J_Content) = 0 Then Exit Sub
Dim JPEG, font_color, font_size, font_family, f_width, f_height, f_Content
Set JPEG = Server.CreateObject("Persits.JPEG")
JPEG.Open Server.MapPath(J_imgurl)
font_size = 10
font_family = "宋体"
f_Left = 5
f_top = 5
If J_fontsize<>"" Then font_size = J_fontsize '字体大小
If J_family<>"" Then font_family = J_family '字体
If J_top<>"" Then f_Left = J_Left '水印离图片左边位置
If J_Left<>"" Then f_top = J_top '水印离图片J_top位置
f_Content = J_Content
' 添加文字水印
JPEG.Canvas.Font.Color = &hff0000 ' 红色
JPEG.Canvas.Font.family = font_family
JPEG.canvas.font.Size = font_size
If J_isbold = 1 Then
JPEG.Canvas.Font.Bold = True
End If
JPEG.Canvas.Print f_Left, f_top, f_Content
JPEG.Save Server.MapPath(J_imgurl)
Set JPEG = Nothing
End Sub
%>
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Oracle存储过程入门学习基本语法
一个小时内学习 SQLite 数据库
![](https://img.aspxhome.com/file/UploadPic/20125/22/2012522185830733.gif)
常用CSS缩写语法总结章
sqlserver中将varchar类型转换为int型再进行排序的方法
![](https://img.aspxhome.com/file/UploadPic/20127/11/2012711161741142.png)
你凭什么说你的网站用户体验好
ASP中如何判断一个字符是不是汉字
ASP中使用Set ors=oConn.Execute()时获取记录数的方法
oracle学习笔记(二)
设计需知:移动网站设计应注意的技术细节
![](https://img.aspxhome.com/file/UploadPic/20124/20/1334303125911-96s.jpg)
完美的js验证网址url(正则表达式)
让你的主页声色并茂—巧为网页添加背景音乐
![](https://img.aspxhome.com/file/UploadPic/20072/200723113013157s.jpg)
asp如何显示SQL数据库所有表的名称?
ASP编程入门进阶教程
![](https://img.aspxhome.com/file/UploadPic/20086/29/2008629183150594s.jpg)
JSONObject.toString
(X)HTML的文档结构
![](https://img.aspxhome.com/file/UploadPic/20086/30/200863012361172s.png)