Listing 1

• 	<cffunction 
• 	name="AddImageInfo" 
• 	access="public" 
• 	returntype="any" 
• 	output="false" 
• 	hint="Takes the image, duplicates it, adds info text to it (graphically), and then returns the resultant image."> 
• 	 
• 	<!--- Define arguments. ---> 
• 	<cfargument 
• 	name="Image" 
• 	type="any" 
• 	required="true" 
• 	/> 
• 	 
• 	<!--- Define the local scope. ---> 
• 	<cfset var LOCAL = {} /> 
• 	 
• 	<!--- 
• 	Copy the image. We don't want to mess up the original 
• 	since the text will ruin it. Here, we have to use the 
• 	ImageCopy() function since Duplicate() will not copy 
• 	the underlying buffered image (at least that's what 
• 	I assume is why Duplicate() doesn't work). 
• 	---> 
• 	<cfset ARGUMENTS.Image = ImageCopy( 
• 	ARGUMENTS.Image, 
• 	0, 
• 	0, 
• 	ARGUMENTS.Image.GetWidth(), 
• 	ARGUMENTS.Image.GetHeight() 
• 	) /> 
• 	 
• 	 
• 	<!--- 
• 	ASSERT: At this point, we have copied the actual 
• 	graphical data into our new image with ImageCopy(). 
• 	This has NOT copied over any of the environmental 
• 	setting (color, antialiasing, etc). We have a clean 
• 	slate in which we must set our own properties. 
• 	---> 
• 	 
• 	 
• 	<!--- 
• 	Now that we have a fresh image, let's build up the 
• 	attribute collection that we are going to use when 
• 	writing the text. This can define the font family, 
• 	size, and style. This CANNOT define the font color. 
• 	That must be set using ImageSetDrawingColor() which 
• 	is done farther below. 
• 	---> 
• 	<cfset LOCAL.Attributes = { 
• 	font = "Courier New", 
• 	size = "14", 
• 	style = "plain" 
• 	} /> 
• 	 
• 	<!--- 
• 	Since our text might be on crazy colored images, we 
• 	are going to write the text first in black for a drop 
• 	shadow, and then we are going to write it in white 
• 	sligtly above that. 
• 	---> 
• 	 
• 	<!--- Create an offset value for the text. ---> 
• 	<cfset LOCAL.Offset = 0 /> 
• 	 
• 	<!--- Loop over the two color choices. ---> 
• 	<cfloop 
• 	index="LOCAL.Color" 

• 	list="##000000,##FFFFFF" 
• 	delimiters=","> 
• 	 
• 	<!--- Set the current color. ---> 
• 	<cfset ImageSetDrawingColor( 
• 	ARGUMENTS.Image, 
• 	"#LOCAL.Color#" 
• 	) /> 
• 	 
• 	 
• 	<!--- 
• 	We want the drop shadow text to be a little bit 
• 	fuzzy (it's a drop shadow). Therefore, if we have 
• 	a zero offset (first go), turn antialiasing on. 
• 	---> 
• 	<cfif LOCAL.Offset> 
• 	 
• 	<!--- Clean text. ---> 
• 	<cfset ImageSetAntialiasing( 
• 	ARGUMENTS.Image, 
• 	"off" 
• 	) /> 
• 	 
• 	<cfelse> 
• 	 
• 	<!--- Fuzzy text. ---> 
• 	<cfset ImageSetAntialiasing( 
• 	ARGUMENTS.Image, 
• 	"on" 
• 	) /> 
• 	 
• 	</cfif> 
• 	 
• 	 
• 	<!--- Write the width overlayed on the image. ---> 
• 	<cfset ImageDrawText( 
• 	ARGUMENTS.Image, 
• 	("Width: " & (ARGUMENTS.Image.GetWidth() & "px")), 
• 	(10 - LOCAL.Offset), 
• 	(20 - LOCAL.Offset), 
• 	LOCAL.Attributes 
• 	) /> 
• 	 
• 	<!--- Write the height overlayed on the image. ---> 
• 	<cfset ImageDrawText( 
• 	ARGUMENTS.Image, 
• 	("Height: " & (ARGUMENTS.Image.GetHeight() & "px")), 
• 	(10 - LOCAL.Offset), 
• 	(38 - LOCAL.Offset), 
• 	LOCAL.Attributes 
• 	) /> 
• 	 
• 	<!--- 
• 	Increment the offset so that the white text 
• 	will be up and left one of the drop shadow. 
• 	---> 
• 	<cfset LOCAL.Offset++ /> 
• 	 
• 	</cfloop> 
• 	 
• 	 
• 	<!--- Return the updated image. ---> 
• 	<cfreturn ARGUMENTS.Image /> 
• 	</cffunction>

Listing 2

• 	<cffunction 
• 	name="AlterImage" 
• 	access="public" 
• 	returntype="any" 
• 	output="false" 

• 	hint="Randomly alters an image and returns it."> 
• 	 
• 	<!--- Define arguments. ---> 
• 	<cfargument 
• 	name="Image" 
• 	type="any" 
• 	required="true" 
• 	/> 
• 	 
• 	<!--- 
• 	Copy the image and overwrite the passed in argument 
• 	value. Since ColdFusion images are passed around by 
• 	referene, this should create a COPY of the image and 
• 	then save that new image reference over the one that 
• 	was passed in. 
• 	---> 
• 	<cfimage 
• 	action="read" 
• 	source="#ARGUMENTS.Image#" 
• 	name="ARGUMENTS.Image" 
• 	/> 
• 	 
• 	<!--- Draw a random line. ---> 
• 	<cfset ImageDrawLine( 
• 	ARGUMENTS.Image, 
• 	RandRange( 0, ARGUMENTS.Image.GetWidth() ), 
• 	RandRange( 0, ARGUMENTS.Image.GetHeight() ), 
• 	RandRange( 0, ARGUMENTS.Image.GetWidth() ), 
• 	RandRange( 0, ARGUMENTS.Image.GetHeight() ) 
• 	) /> 
• 	 
• 	<!--- Return the altered image. ---> 
• 	<cfreturn ARGUMENTS.Image /> 
• 	</cffunction>

Listing 3

• 	<!--- Read in the original image. ---> 
• 	<cfimage 
• 	action="read" 
• 	source="./mud_monster.jpg" 
• 	name="objImage" 
• 	/> 
• 	 
• 	<!--- Resize image. ---> 
• 	<cfimage 
• 	action="resize" 
• 	source="#objImage#" 
• 	width="35%" 
• 	height="35%" 
• 	name="objImage" 
• 	/> 
• 	 	 
• 	<!--- 
• 	Write the image to the browser three times. For each 
• 	write, alter the image. Notice that we are not storing 
• 	the AlterImage() return value anywhere. 
• 	---> 
• 	<cfimage 
• 	action="writetobrowser" 
• 	source="#AlterImage( objImage )#" 
• 	/> 
• 	 
• 	<cfimage 
• 	action="writetobrowser" 
• 	source="#AlterImage( objImage )#" 
• 	/> 
• 	 
• 	<cfimage 
• 	action="writetobrowser" 
• 	source="#AlterImage( objImage )#" 
• 	/>

Listing 4

• 	<!--- Read in the existing image to a new variable name. ---> 
• 	<cfimage 
• 	action="read" 
• 	source="#objImage#" 
• 	name="objNewImage" 
• 	/> 
• 	 
• 	<!--- Now, add a border to the new image. ---> 
• 	<cfimage 
• 	action="border" 
• 	source="#objNewImage#" 
• 	thickness="2" 
• 	color="##0000CC" 
• 	name="objNewImage" 
• 	/> 
• 	 
• 	<!--- Now, output both the original image and the image. ---> 
• 	<cfimage 
• 	action="writetobrowser" 
• 	source="#objImage#" 
• 	/> 
• 	 
• 	<cfimage 
• 	action="writetobrowser" 
• 	source="#objNewImage#" 
• 	/>

Listing 5

• 	<!--- Loop over the various CAPTCHA difficulties. ---> 
• 	<cfloop 
• 	index="strDifficulty" 
• 	list="low,medium,high" 
• 	delimiters=","> 
• 	 
• 	<!--- Output the CAPTCHA image to the browser. ---> 
• 	<cfimage 
• 	action="captcha" 
• 	height="75" 
• v	width="363" 
• 	text="KinkySolutions" 
• 	difficulty="#strDifficulty#" 
• 	fonts="verdana,arial,times new roman,courier" 
• 	fontsize="18" 
• 	/> 
• 	 
• 	<br /> 
• 	 
• 	</cfloop>

Listing 6

• 	<!--- Read in large mud monster. ---> 
• 	<cfimage 
• 	action="read" 
• 	source="./mud_monster_large.jpg" 
• 	name="objLargeImage" 
• 	/> 
• 	 
• 	<!--- 
• 	Loop over the original mud monster image 10 times 
• 	for each level of percentage reduction. Notice that 
• 	each resizing actually acts on the original image, 
• 	not the previously resized image. 
• 	---> 
• 	<cfloop 
• 	index="intScale" 
• 	from="100" 
• 	to="10" 
• 	step="-10"> 
• 	 
• 	<!--- Resize the image to the current scale. ---> 
• 	<cfimage 
• 	action="resize" 
• 	source="#objLargeImage#" 
• 	width="#intScale#%" 
• 	height="#intScale#%" 
• 	name="objImage" 
• 	/> 
• 	 
• 	<!--- 
• 	Here, I am addint the image info before writing it 
• 	to the browser. I am doing this because I am going 
• 	to crop the image and I want you to see the true 
• 	dimensions at the time of resacling. 
• 	---> 
• 	<cfset objImage = AddImageInfo( objImage ) /> 
• 	 
• 	<!--- 
• 	Crop the image. I am only doing this so it 
• 	will display nicely on the page. 
• 	---> 
• 	<cfset ImageCrop( 
• 	objImage, 
• 	0, 
• 	0, 
• 	Min( objImage.GetWidth(), 545 ), 
• 	Min( objImage.GetHeight(), 408 ) 
• 	) /> 
• 	 
• 	<!--- Write the image to the browser. ---> 
• 	<cfimage 
• 	action="writetobrowser" 
• 	source="#objImage#" 
• 	format="jpg" 
• 	/> 
• 	 
• 	<br /> 
• 	 
</cfloop>