2) Drawing the text
We will be using similar code as I mentioned in the example, except, the method will be slightly different. For ease of use, we will separate the form processing code and image generation code in two separate files. We will create an ASP file to generate the image and then insert that image into our form at run time. The code to generate the image is as below, save it in a file called genImage.asp':
Code:
<%@Language=VBScript%>
<%
Dim strWord
Dim intImageWidth
Dim intImageHeight
Dim oDynImage
strWord = "12345"
intImageWidth = 300
intImageHeight = 150
Set oDynImage = CreateObject("DynImage.DynImage")
With oDynImage
.Open intImageWidth, intImageHeight
.FontFace = "Arial"
.FontWeight = 800
.FontSize = 48
.TextAlign = 5
.TextOut (intImageWidth/2), (intImageHeight/2), strWord
Response.ContentType = "image/png"
Response.BinaryWrite .Image
.Close
End With
Set oDynImage = Nothing
%>
The code is quite similar to what we saw earlier with a few additions. Ive set the font face, weight size and alignment properties. For now it just draws the string 12345 in the exact center of the image. Well replace it a string of our choice later. When browsed it will display the below image: