ASP implementation-gif format without component generation verification code

Source: Internet
Author: User
Tags abs format array count image identifier sin
No Components | verification Code

<%
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 (1,)
Dotdata (1) = Array (1, 34, 30, 1, 71, 1, 100, 1 (2) = Array (1, 1, dotdata, 1,, 1, m)
Dotdata (3) = Array (1) = X (+) (+.) = Dotdata, 6, 6, 4) = Array (1, 1, 1, 1, X, M, M, M, 1,%)
Dot (+)
) = (+) = Data (5) = Array (+, 1, 1, 1, 1,, M, 1, MB, MB, x, M, x, x)
Dotdata----- (6) = Array (6, 6, 6,, 6,)
Dotdata (7) = Array (100, 30, 100, 20, 70, 1, 30, 1, 1, 20, 1, 30, 100, 70, 100 , 1, 1, dotdata (8) = Array (1, 80, 30, 100, 80, 100, 100, 70, 100, 20, 70, 1, 30,)
). 1, 1, 1, M, M, (+)

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.bi Narywrite ChrB (1-graph (x, y))
Else
If x * (x-width) = 0 Or y * (y-height) = 0 Then
Response.BinaryWrite ChrB (grap H (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< Br>response.binarywrite ChrB (0)
End If
"End If"
End If
if (Y * Width + x + 1) Mod 126 = 0 Then
Response.binar Ywrite 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
-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.