Do You Have A Permit For Those Guns?

<!--- This is the function that adds text to the permit. --->
<cffunction
	name="AddPermitText"
	access="public"
	returnvariable="any"
	output="true"
	hint="Adds text to the image given gun permit.">
 
	<!--- Define arguments. --->
	<cfargument
		name="Permit"
		type="any"
		required="true"
		hint="The permit image object."
		/>
 
	<cfargument
		name="Text"
		type="string"
		required="true"
		hint="The text to be applied."
		/>
 
	<cfargument
		name="X"
		type="numeric"
		required="true"
		hint="The X coordinate of the text."
		/>
 
	<cfargument
		name="Y"
		type="numeric"
		required="true"
		hint="The Y coordinate of the text."
		/>
 
	<!--- Define the local scope. --->
	<cfset var LOCAL = {} />
 
 
	<!--- Turn anti-aliasing on for nice text rendering. --->
	<cfset ImageSetAntialiasing( ARGUMENTS.Permit, "on" ) />
 
	<!--- Set the drawing color. --->
	<cfset ImageSetDrawingColor(
		ARGUMENTS.Permit,
		"##454545"
		) />
 
	<!--- Create the font attributes collection. --->
	<cfset LOCAL.FontAttributes = {
		Font = "Courier New",
		Size = "20"
		} />
 
	<!--- Draw the text. --->
	<cfset ImageDrawText(
		ARGUMENTS.Permit,
		ARGUMENTS.Text,
		ARGUMENTS.X,
		ARGUMENTS.Y,
		LOCAL.FontAttributes
		) />
 
 
	<!--- Return the updated image. --->
	<cfreturn ARGUMENTS.Permit />
</cffunction>
 
 
 
 
<!--- Param form variables. --->
<cfparam name="FORM.name" type="string" default="" />
<cfparam name="FORM.birthday" type="string" default="" />
<cfparam name="FORM.forearm" type="string" default="" />
<cfparam name="FORM.arm" type="string" default="" />
<cfparam name="FORM.weight" type="string" default="" />
<cfparam name="FORM.height" type="string" default="" />
 
 
<!--- Create an array to hold form errors. --->
<cfset arrErrors = ArrayNew( 1 ) />
 
<!---
	Read in the background image to act as our permit canvas.
	This includes the design and all the non-dynamic text.
--->
<cfimage
	action="read"
	source="./gun_permit.gif"
	name="objPermit"
	/>
 
 
 
<!---
	Check to see if the form has been submitted. We will
	know this if there are any fields listed.
--->
<cfif StructKeyExists( FORM, "FieldNames" )>
 
	<!--- Validate form data. --->
	<cfif NOT Len( FORM.name )>
 
		<cfset ArrayAppend(
			arrErrors,
			"Please enter your name."
			) />
 
	</cfif>
 
	<cfif NOT IsNumericDate( FORM.birthday )>
 
		<cfset ArrayAppend(
			arrErrors,
			"Please enter your birthday (mm/dd/yyyy)."
			) />
 
	</cfif>
 
	<cfif NOT Val( FORM.forearm )>
 
		<cfset ArrayAppend(
			arrErrors,
			"Please enter your forearm circumference in inches."
			) />
 
	</cfif>
 
	<cfif NOT Val( FORM.arm )>
 
		<cfset ArrayAppend(
			arrErrors,
			"Please enter your upper arm circumference in inches."
			) />
 
	</cfif>
 
	<cfif NOT Len( FORM.weight )>
 
		<cfset ArrayAppend(
			arrErrors,
			"Please enter your weight."
			) />
 
	</cfif>
 
	<cfif NOT Len( FORM.height )>
 
		<cfset ArrayAppend(
			arrErrors,
			"Please enter your height."
			) />
 
	</cfif>
 
 
	<!--- Check to see if any validation errors were found. --->
	<cfif NOT ArrayLen( arrErrors )>
 
		<!--- Date issued. --->
		<cfset AddPermitText(
			objPermit,
			DateFormat( Now(), "mm-dd-yyyy" ),
			375,
			53
			) />
 
		<!--- Printed name.. --->
		<cfset AddPermitText(
			objPermit,
			FORM.name,
			26,
			103
			) />
 
		<!--- Date of birth. --->
		<cfset AddPermitText(
			objPermit,
			DateFormat( FORM.birthday, "mm-dd-yyyy" ),
			375,
			103
			) />
 
		<!--- Forearm size. --->
		<cfset AddPermitText(
			objPermit,
			"#NumberFormat( Val( FORM.forearm ), '0.0' )#""",
			26,
			153
			) />
 
		<!--- Upper arm size. --->
		<cfset AddPermitText(
			objPermit,
			"#NumberFormat( Val( FORM.arm ), '0.0' )#""",
			155,
			153
			) />
 
		<!--- Weight. --->
		<cfset AddPermitText(
			objPermit,
			FORM.weight,
			284,
			153
			) />
 
		<!--- Height. --->
		<cfset AddPermitText(
			objPermit,
			FORM.height,
			413,
			153
			) />
 
		<!--- Name and title of officer. --->
		<cfset AddPermitText(
			objPermit,
			"Inspector in",
			330,
			180
			) />
 
		<!--- Name and title of officer. --->
		<cfset AddPermitText(
			objPermit,
			"Charge",
			330,
			203
			) />
 
		<!--- Name and address of location. --->
		<cfset AddPermitText(
			objPermit,
			"Project Huge Fitness New York, NY 10011",
			26,
			253
			) />
 
		<!--- Badge no. --->
		<cfset AddPermitText(
			objPermit,
			RandRange( 1000, 9999 ),
			413,
			291
			) />
 
		<!--- Permit no. --->
		<cfset AddPermitText(
			objPermit,
			RandRange( 1000, 9999 ),
			413,
			322
			) />
 
	</cfif>
 
</cfif>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Gun Permit Using ColdFusion 8</title>
 
	<style type="text/css">
 
		body {
			font-family: verdana, arial, sans-serif ;
			font-size: 62.5% ;
			}
 
		div.errors {
			color: #CC0000 ;
			}
 
		div.errors h4 {
			font-size: 1.4em ;
			font-weight: bold ;
			margin-bottom: 7px ;
			}
 
		div.errors ul {
			font-size: 1.2em ;
			line-height: 1.4em ;
			margin-top: 0px ;
			}
 
		form {
			position: relative ;
			}
 
		label {
			display: block ;
			font-size: 1.4em ;
			margin-bottom: 5px ;
			}
 
		input {
			display: block ;
			margin-left: .5in ;
			width: 175px ;
			}
 
		div#permit {
			border: 1px solid #333333 ;
			left: 325px ;
			position: absolute ;
			width: 545px ;
			top: 5px ;
			z-index: 100 ;
			}
 
	</style>
</head>
<body>
 
	<cfoutput>
 
		<h1>
			Gun Permit Using ColdFusion 8
		</h1>
 
 
		<!--- Check to see if there are any errors. --->
		<cfif ArrayLen( arrErrors )>
 
			<div class="errors">
 
				<h4>
					Please review the following:
				</h4>
 
				<ul>
					<cfloop
						index="strError"
						array="#arrErrors#">
 
						<li>
							#strError#
						</li>
 
					</cfloop>
				</ul>
 
			</div>
 
		</cfif>
 
 
		<form action="#CGI.script_name#" method="post">
 
			<label for="name">
				Name (First, Middle initial, Last):
			</label>
 
			<input
				type="text"
				name="name"
				id="name"
				value="#HtmlEditFormat( FORM.name )#"
				/>
 
			<br />
 
			<label for="name">
				Birthday (mm/dd/yyyy):
			</label>
 
			<input
				type="text"
				name="birthday"
				id="birthday"
				value="#HtmlEditFormat( FORM.birthday )#"
				/>
 
			<br />
 
			<label for="forearm">
				Forearm Circumference:
			</label>
 
			<input
				type="text"
				name="forearm"
				id="forearm"
				value="#HtmlEditFormat( FORM.forearm )#"
				/>
 
			<br />
 
			<label for="forearm">
				Upper Arm Circumference:
			</label>
 
			<input
				type="text"
				name="arm"
				id="arm"
				value="#HtmlEditFormat( FORM.arm )#"
				/>
 
			<br />
 
			<label for="weight">
				Weight:
			</label>
 
			<input
				type="text"
				name="weight"
				id="weight"
				value="#HtmlEditFormat( FORM.weight )#"
				/>
 
			<br />
 
			<label for="weight">
				Height (F'I&quot;):
			</label>
 
			<input
				type="text"
				name="height"
				id="height"
				value="#HtmlEditFormat( FORM.height )#"
				/>
 
			<br />
 
			<input
				type="submit"
				value="Build Gun Permit &raquo;"
				/>
 
 
			<!--- Write to the browser. --->
			<div id="permit">
 
				<cfimage
					action="writetobrowser"
					source="#objPermit#"
					format="gif"
					/>
 
			</div>
 
		</form>
 
	</cfoutput>
 
</body>
</html>

For Cut-and-Paste