<% ' Declare option explicit Option Explicit ' Set the session timeout to be 10 minutes, as filling in a guestbook shouldn't take long 'Session.Timeout = 10 ' Run randomize to make sure a random number is retrieved Randomize ' Declare the variables Dim jpeg Dim pixelsAcross Dim backColour Dim borderColour Dim textColour ' The background colour of the image (the last 6 letters are the HTML hex colour code) backColour = &HFFFFFF ' The border colour borderColour = &H896E5C ' The text colour textColour = &H896E5C ' The initial pixels across, where the text starts from pixelsAcross = 10 ' Create the jpeg object Set jpeg = Server.CreateObject("Persits.jpeg") ' Create a new image of size 130x40 with the defined colour background jpeg.new 130, 50, backColour ' Draw a border around the image drawBorder ' Run the sub which does the lettering doString ' Draw random lines over the image drawLines ' Return the binary, which sets this page a jpeg jpeg.SendBinary ' Sub to draw a border around the image Sub drawBorder ' Set the pen colour to be blue jpeg.Canvas.Pen.Color = borderColour ' Sets it so the whole image isn't painted, just the border that is to be drawn jpeg.Canvas.Brush.Solid = False ' Draw a border around the image jpeg.Canvas.DrawBar 0, 0, jpeg.Width, jpeg.Height End Sub ' Sub to draw random lines on the image Sub drawLines ' Set the pen colour as the same colour as the text jpeg.Canvas.Pen.Color = textColour ' Draw a border around the image jpeg.Canvas.DrawLine 0, Int(Rnd * 40), jpeg.Width, Int(Rnd * 40) ' Draw a border around the image jpeg.Canvas.DrawLine 0, Int(Rnd * 40), jpeg.Width, Int(Rnd * 40) jpeg.Canvas.DrawLine 0, Int(Rnd * 40), jpeg.Width, Int(Rnd * 40) End Sub ' Sub to do the lettering Sub doString ' Define the local variables that are used Dim theString Dim x ' Get the string theString = createRandomString() ' Loop through each letter of the string For x = 1 to len(theString) ' Add the letter at the current position addLetter(Mid(theString, x, 1)) Next End Sub ' Sub to print a letter Sub addLetter(theLetter) ' Set the font colour to be the defined colour jpeg.Canvas.Font.Color = textColour ' Maybe set as bold if doTextStyle then jpeg.Canvas.Font.Bold = True End If ' Maybe set as underlined if doTextStyle then jpeg.Canvas.Font.Underlined = False End If ' Maybe set as italic if doTextStyle then jpeg.Canvas.Font.Italic = True End If ' Set the font to be arial jpeg.Canvas.Font.Family = randomFont() ' Set the size to be 15 jpeg.Canvas.Font.Size = randomFontSize() ' Antialias the text jpeg.Canvas.Font.Quality = 4 ' Set the backcolour to be the same as the image background jpeg.Canvas.Font.BkColor = backColour ' Set the test background color to be opaque and not transparent jpeg.Canvas.Font.BkMode = "Opaque" ' Print the letter jpeg.canvas.print pixelsAcross, 10, theLetter ' Add 19 to how many pixels across the text should be pixelsAcross = pixelsAcross + 20 End Sub ' Function that returns a true or false on a 50/50 basis Function doTextStyle() ' If a random number is above 0.5 return true, else return false if Rnd() > 0.5 then doTextStyle = true else doTextStyle = false end if End Function ' Function to return a random font size Function randomFontSize() ' Define the local variable used Dim theNumber ' Get a random number, multiply by 14, change to an int and add 18 (so always above 18 and below 32) theNumber = Int(Rnd * 14) + 18 ' Return the number randomFontSize = theNumber End Function ' Function to return a random font Function randomFont() ' Define the local variables used Dim theNumber Dim font ' Get a random number theNumber = Rnd ' Use a long if-then-else on the random number for 5 possible fonts if theNumber < 0.2 then font = "Arial" elseif theNumber < 0.4 then font = "Courier New" elseif theNumber < 0.6 then font = "Helvetica" elseif theNumber < 0.8 then font = "Verdana" else font = "Geneva" end if ' Return the font randomFont = font End Function ' Function to create a random string Function createRandomString() ' Define the local variables used Dim outputString Dim x ' Loop 5 times For x = 0 To 4 ' 60% of the time a letter will be added, 40% will be a number if rnd() < 0.6 then ' Add a random capital letter to the string outputString = outputString & Chr(Int((26 * rnd()) + 65)) else ' Add a number to the string outputString = outputString & Chr(Int((10 * rnd()) + 48)) end if Next ' Store the output string to a session Session("image_ver") = outputString ' Return the string createRandomString = outputString End Function ?>