ASP implementation of non-component generated GIF format verification code

Source: Internet
Author: User
Tags abs image identifier sin

<%
Option Explicit ' Display declaration
Class Com_gifcode_class
'''''''''''''''''''''''''''''''''''''''''''''
' Author:layen support@ssaw.net 84815733 (QQ)
' Thanks:laomi, Laomiao, Netrube
' 2006-01-02
'''''''''''''''''''''''''''''''''''''''''''''
Public noisy, Count, Width, Height, Angle, Offset, Border
Private Graph (), Margin (3)
Private Sub Class_Initialize ()
Randomize
Noisy = 16 ' probability of interference points appearing
Count = 4 ' character quantity
width = 80 ' picture widths
Height = 20 ' picture Heights
Angle = 2 ' angular random change amount
offset = 20 ' offset random change amount
Border = 1 ' border size
End Sub
Public Function Create ()
Const ccharset = "123456789"
Dim I, X, y
Dim Vvalidcode:vvalidcode = ""
Dim Vindex
ReDim Graph (Width-1, Height-1)
For i = 0 to Count-1
Vindex = Int (Rnd * Len (Ccharset))
Vvalidcode = Vvalidcode + Mid (Ccharset, vindex+1, 1)
Setdraw Vindex, I
Next
Create = Vvalidcode
End Function
Sub Setdot (PX, PY)
If PX * (width-px-1) >= 0 and PY * (height-py-1) >= 0 Then
Graph (PX, PY) = 1
End If
End Sub
Public Sub Setdraw (Pindex, Pnumber)
' Character data
Dim Dotdata (8)
Dotdata (0) = Array (30, 15, 50, 1, 50, 100)
Dotdata (1) = Array (1, 34, 30, 1, 71, 1, 100, 34, 1, 100, 93, 100, 100, 86)
Dotdata (2) = Array (1, 1, 100, 1, 42, 42, 100, 70, 50, 100, 1, 70)
Dotdata (3) = Array (100, 73, 6, 73, 75, 6, 75, 100)
Dotdata (4) = Array (100, 1, 1, 1, 1, 50, 50, 35, 100, 55, 100, 80, 50, 100, 1, 95)
Dotdata (5) = Array (100, 20, 70, 1, 20, 1, 1, 30, 1, 80, 30, 100, 70, 100, 100, 80, 100, 60, 70, 50, 30, 50, 1, 60)
Dotdata (6) = Array (6, 26, 6, 6, 100, 6, 53, 100)
Dotdata (7) = Array (100, 30, 100, 20, 70, 1, 30, 1, 1, 20, 1, 30, 100, 70, 100, 80, 70, 100, 30, 100, 1, 80, 1, 70, 100, 30 )
Dotdata (8) = Array (1, 80, 30, 100, 80, 100, 100, 70, 100, 20, 70, 1, 30, 1, 1, 20, 1, 40, 30, 50, 70, 50, 100, 40)
Dim vextent:vextent = Width/count
Margin (0) = Border + vextent * (RND * Offset)/MB + Margin (1)
Margin (1) = Vextent * (pnumber + 1)-Border-vextent * (RND * Offset)/100
Margin (2) = Border + Height * (RND * Offset)/100
Margin (3) = Height-border-height * (RND * Offset)/100
Dim Vstartx, Vendx, Vstarty, Vendy
Dim vwidth, Vheight, VDX, Vdy, Vdeltat
Dim Vangle, Vlength
Vwidth = Int (Margin (1)-Margin (0))
Vheight = Int (Margin (3)-Margin (2))
' Start coordinates
Vstartx = Int ((Dotdata (Pindex) (0)-1) * vwidth/100)
Vstarty = Int ((Dotdata (Pindex) (1)-1) * vheight/100)
Dim I, J
For i = 1 to UBound (Dotdata (Pindex), 1)/2
If Dotdata (Pindex) (2*i-2) <> 0 and Dotdata (pindex) (2*i) <> 0 Then
' Endpoint coordinates
Vendx = (Dotdata (pindex) (2*i)-1) * vwidth/100
Vendy = (Dotdata (pindex) (2*i+1)-1) * vheight/100
' Horizontal gap
VDX = Vendx-vstartx
' Vertical gap
Vdy = Vendy-vstarty
' Tilt angle
If VDX = 0 Then
Vangle = SGN (vdy) * 3.14/2
Else
Vangle = Atn (VDY/VDX)
End If
' Two coordinate distance
If Sin (Vangle) = 0 Then
Vlength = VDX
Else
Vlength = Vdy/sin (vangle)
End If
' Random rotation angle
Vangle = Vangle + (Rnd-0.5) * 2 * Angle * 3.14 * 2/100
VDX = Int (Cos (vangle) * vlength)
Vdy = Int (Sin (vangle) * vlength)
If ABS (VDX) > abs (vdy) Then Vdeltat = ABS (VDX) Else Vdeltat = ABS (Vdy)
For j = 1 to Vdeltat
Setdot Margin (0) + Vstartx + J * Vdx/vdeltat, Margin (2) + Vstarty + J * Vdy/vdeltat
Next
Vstartx = Vstartx + VDX
Vstarty = Vstarty + Vdy
End If
Next
End Sub
Public Sub Output ()
Response.Expires =-9999
Response.AddHeader "Pragma", "No-cache"
Response.AddHeader "Cache-ctrol", "No-cache"
Response.ContentType = "Image/gif"
' File type
Response.BinaryWrite ChrB (ASC ("G")) & ChrB (ASC ("I")) & ChrB (ASC ("F"))
' Version information
Response.BinaryWrite ChrB (ASC ("8")) & ChrB (ASC ("9")) & ChrB (ASC ("a"))
' Logical screen width
Response.BinaryWrite ChrB (width mod 256) & ChrB ((width \256) mod 256)
' Logical screen Height
Response.BinaryWrite ChrB (height mod 256) & ChrB ((height \256) mod 256)
Response.BinaryWrite ChrB (128) & ChrB (0) & ChrB (0)
' Global Color list
Response.BinaryWrite ChrB (255) & ChrB (255) & ChrB (255)
Response.BinaryWrite ChrB (0) & ChrB () & ChrB (255)
' Image identifier
Response.BinaryWrite ChrB (ASC (","))
Response.BinaryWrite ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0)
' Image width
Response.BinaryWrite ChrB (width mod 256) & ChrB ((width \256) mod 256)
' Image height
Response.BinaryWrite ChrB (height mod 256) & ChrB ((height \256) mod 256)
Response.BinaryWrite ChrB (0) & ChrB (7) & ChrB (255)
Dim x, y, i:i = 0
For y = 0 to Height-1
For x = 0 to Width-1
If Rnd < noisy/100 Then
Response.BinaryWrite ChrB (1-graph (x, y))
Else
If x * (x-width) = 0 Or y * (y-height) = 0 Then
Response.BinaryWrite ChrB (Graph (x, y))
Else
If graph (x-1, y) = 1 or graph (x, y) or graph (x, y-1) = 1 Then
Response.BinaryWrite ChrB (1)
Else
Response.BinaryWrite ChrB (0)
End If
End If
End If
If (Y * Width + x + 1) Mod 126 = 0 Then
Response.BinaryWrite ChrB (128)
i = i + 1
End If
If (Y * Width + x + i + 1) Mod 255 = 0 Then
If (WIDTH*HEIGHT-Y * width-x-1) > 255 Then
Response.BinaryWrite ChrB (255)
Else
Response.BinaryWrite ChrB (Width * Height Mod 255)
End If
End If
Next
Next
Response.BinaryWrite ChrB (128) & ChrB (0) & ChrB (129) & ChrB (0) & ChrB (59)
End Sub
End Class
Dim Mcode
Set Mcode = New Com_gifcode_class
Session ("GetCode") = Mcode.create ()
Mcode.output ()
Set Mcode = Nothing
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.