Sometimes you generate text dynamically in ASP file that you want to appear in a JPG image file.

Some ISP's have, or will, install some software called ASPImage. If you cannot find one, EMail me and I will put you in touch with one that has.

Below is an example of the contents of an ASP file called GenerateImage.asp



<%


function generateImage(cImgFileName, cImgTextStr, cImgFontColour, cImgTopColour, cImgBottomColour)


	Set Image = Server.CreateObject("AspImage.Image")

	stringVChar = cImgTextStr & " "

	rem Set various font parameters

	Image.FontColor = getColourNumber(cImgFontColour)

	Image.Italic = True

	Image.Bold = True

	Image.FontName = "Arial"

	Image.FontSize = 12

	Image.PadSize = 10



	rem Calculate how big our text info is and set the image to this size

	rem  This has to be done since we want to fill the area with a gradient

	strMessage = stringVChar

	Image.MaxX = Image.TextWidth (strMessage)

	Image.MaxY = Image.TextHeight (strMessage)



	rem Create a one way gradient

	Image.GradientOneWay getColourNumber(cImgTopColour), getColourNumber(cImgBottomColour), 0



	rem Print our string to the image

	Image.TextOut strMessage, Image.X, Image.Y, false



	rem Set the filename and save

	rem   NOTE: You should gen the filename dynamically for multiuser usage

	Image.FileName = cImgFileName

	if Image.SaveImage then

		rem The image was saved so reply "OK"

		generateImage = "OK"

	else

		rem Something happened and we couldn't save the image so reply "FAIL"

		generateImage = "FAIL"

	end if

end function



function getColourNumber (cGCN)
	nGCN = 0
	nGCN = nGCN + (hexToInt(Mid(cGCN,2,1)) * 1)
	nGCN = nGCN + (hexToInt(Mid(cGCN,1,1)) * 16)
	nGCN = nGCN + (hexToInt(Mid(cGCN,4,1)) * 16 * 16)
	nGCN = nGCN + (hexToInt(Mid(cGCN,3,1)) * 16 * 16 * 16)
	nGCN = nGCN + (hexToInt(Mid(cGCN,6,1)) * 16 * 16 * 16 * 16)
	nGCN = nGCN + (hexToInt(Mid(cGCN,5,1)) * 16 * 16 * 16 * 16 * 16)

	getColourNumber = nGCN
end function



function hexToInt (cHTI)
	if IsNumeric(cHTI) then
		hexToInt = cHTI
	else
		hexToInt = Asc(UCase(cHTI)) - 64 + 9
	end if
end function



%>



It can be used in any other ASP file in the way shown below.



<!--#include file="generateImage.asp"-->

<%
Response.Expires = 0
session.LCID = 2057

Application("AppTimeNo") = Application("AppTimeNo") + 1
SecDef = DateDiff("s",date,now)
If SecDef <> Application("SecDef") Then
	Application("AppTimeNo") = 1
End If
Application("SecDef") = SecDef
ReplyFile1 = (SecDef * 100) + Application("AppTimeNo")
ReplyFile = "C:\Servers\Clients\217072167102\oldpod\sst\www\" & ReplyFile1 & ".JPG"
RedirectFile = ReplyFile1 & ".JPG"

inStringText = "A test" & VbCrLf & Now

gIResult = generateImage(ReplyFile, inStringText, "0000ff", "ffff00", "ff0000")

if gIResult = "OK" then
	Response.Redirect RedirectFile
else
	Response.Write "Sorry, it was not possible to generate and save an image"
end if


%>


To see it in action, point to and click here