Styling The ColdFusion 8 WriteToBrowser CFImage Output

<cffunction
	name="ImageWriteToBrowserCustom"
	access="public"
	returntype="void"
	output="true"
	hint="Writes the image to the browser with additional attributes.">
 
	<!--- Define arguments. --->
	<cfargument
		name="Image"
		type="any"
		required="true"
		hint="The ColdFusion image object that you are writing to browser."
		/>
 
	<cfargument
		name="Alt"
		type="string"
		required="false"
		default=""
		hint="The ALT attribute value to apply to the image."
		/>
 
	<cfargument
		name="Class"
		type="string"
		required="false"
		default=""
		hint="The CSS class to apply to the image."
		/>
 
	<cfargument
		name="Style"
		type="string"
		required="false"
		default=""
		hint="The STYLE attribute value to apply to the image."
		/>
 
	<cfargument
		name="Height"
		type="string"
		required="false"
		default=""
		hint="The HEIGHT attribute value to apply to the image."
		/>
 
	<cfargument
		name="Width"
		type="string"
		required="false"
		default=""
		hint="The WIDTH attribute value to apply to the image."
		/>
 
	<cfargument
		name="Border"
		type="string"
		required="false"
		default=""
		hint="The BORDER attribute value to apply to the image."
		/>
 
 
	<!--- Define the local scope. --->
	<cfset var LOCAL = {} />
 
 
	<!---
		Write the image to the browser. This is really just
		creating the image and then writing to the buffer.
		All we have to do is intercept the buffer write.
	--->
	<cfsavecontent variable="LOCAL.Output">
		<cfoutput>
 
			<!--- Write image tag. --->
			<cfimage
				action="writetobrowser"
				source="#ARGUMENTS.Image#"
				/>
 
		</cfoutput>
	</cfsavecontent>
 
	<!---
		First, delete any existing attributes that we might
		be using (so that we can just add new ones).
	--->
	<cfset LOCAL.Output = LOCAL.Output.ReplaceAll(
		"(?i) (alt|class|style|height|width|border)=""[^""]*""",
		""
		) />
 
	<!---
		Now that we have an image with Just the SRC
		attribute, we can go about adding our attributes.
		First, chop off the trailing slash.
	--->
	<cfset LOCAL.Output = LOCAL.Output.ReplaceFirst(
		"\s*/?>\s*$",
		""
		) />
 
	<!---
		Loop over the arguments to see if we need to
		add them to the tag.
	--->
	<cfloop
		index="LOCAL.Key"
		list="alt,class,style,height,width,border"
		delimiters=",">
 
		<!--- Check for a passed-in value. --->
		<cfif Len( ARGUMENTS[ LOCAL.Key ] )>
 
			<!---
				Append this argument to the output and a
				key-value attribute.
			--->
			<cfset LOCAL.Output &= (
				" " &
				LOCAL.Key &
				"=""" &
				ARGUMENTS[ LOCAL.Key ] &
				""""
				) />
 
		</cfif>
 
	</cfloop>
 
	<!--- Write the image tag to the output. --->
	<cfset WriteOutput( LOCAL.Output & " />" ) />
 
	<!--- Return out. --->
	<cfreturn />
</cffunction>

For Cut-and-Paste