Description of "specialcounter.asp"

This script has two sections. The first part uses the File System Object and reads the current count from a text file. It increments the count and creates a new text file containing the new value.

The count is reset to zero at 10000 and it is converted to a string with leading zeros where appropriate.

The second part of the script works with the image. It loads the blank original image and then sets the text properties. The word "HITS" and the count total both use the Tahoma font, but the count is bigger and uses a bold style.

<%
Response.Expires = 0
Response.Buffer = true
Response.Clear

Set FileStreamObj = CreateObject("Scripting.FileSystemObject")

Set TextFile = FileStreamObj.OpenTextFile(Server.MapPath("count.txt")
Count = TextFile.Readline
TextFile.Close

Count = Count + 1

If Count > 9999 Then
  Count = 0
End If

Set NewFile = FileStreamObj.CreateTextFile(Server.MapPath("count.txt")
NewFile.WriteLine(Count)
NewFile.Close

Count = CStr(Count)
While Len(Count) < 4
  Count = "0" & Count
Wend

Set Image = Server.CreateObject("csImageFile.Manage")
Image.ReadFile Server.MapPath("images/specialcount.png")
Image.TextOpaque = false
Image.TextSize = 20
Image.TextColor = "000000"
Image.TextFont = "Tahoma"
Image.Text 200, 115, "HITS"

Image.TextBold = true
Image.TextSize = 38
Image.Text 215, 145, Count

Response.ContentType = "image/gif"
Response.BinaryWrite Image.GIFData
%>

Additional notes:

If this script is used with the trial component "csImageFile" must be replaced with "csImageFileTrial".

We stream the image to the browser in GIF format. The Transparent and TransparentColor properties have both had their values set when the PNG file was loaded. Also, the content type should be set to indicate the correct image type. In the past an incorrect MIME type would cause problems with some browsers but modern browsers are much more forgiving.

A lot of the ASP code in this script is used to read and increment the count. csImageFile is only used to add the text to the image. Text can be added to images in this way in a wide variety of applications.