Learning ColdFusion 8: CFImage Part III - Watermarks And Transparency

<!--- Read in the original image. --->
<cfset objImage = ImageRead( "./blue_eyes.jpg" ) />
 
 
<!---
	Create a new image for the watermark with the given
	dimensions and give it a very light gray cavnas color.
--->
<cfset objWatermark = ImageNew(
	"",
	100,
	20,
	"rgb",
	"##F0F0F0"
	) />
 
 
<!---
	Set the drawing color. This will be the color
	for all image manipulations going forward.
--->
<cfset ImageSetDrawingColor(
	objWatermark,
	"##666666"
	) />
 
<!--- Draw the rectangle. --->
<cfset ImageDrawRect(
	objWatermark,
	0,
	0,
	(objWatermark.GetWidth() - 1),
	(objWatermark.GetHeight() - 1)
	) />
 
<!---
	Set text drawing anti aliasing. This will give are
	text a smoother rendered look (rather than jagged
	text you would see on a web page).
--->
<cfset ImageSetAntialiasing(
	objWatermark,
	"on"
	) />
 
<!--- Create text attributes. --->
<cfset objAttributes = {
	Font = "Verdana",
	Size = "10",
	Style = "Italic"
	} />
 
<!--- Draw the watermark text onto our watermark image. --->
<cfset ImageDrawText(
	objWatermark,
	"Kinky Solutions",
	11,
	14,
	objAttributes
	) />
 
<!---
	When we paste the watermark onto the photo, we don't
	want it to be fully visible. Therefore, let's set the
	drawing transparency to 50% before we paste.
--->
<cfset ImageSetDrawingTransparency(
	objImage,
	50
	) />
 
<!---
	Paste the manually created watermark image onto the photo.
	This time, we don't need to turn on any anti aliasing since
	the watermark has solid borders. The anti alisasing only
	helps us when the pasted image has anti aliased perimeter.
--->
<cfset ImagePaste(
	objImage,
	objWatermark,
	(objImage.GetWidth() - objWatermark.GetWidth() - 3),
	(objImage.GetHeight() - objWatermark.GetHeight() - 3)
	) />
 
<!--- Write the image with the new watermark to the browser. --->
<cfimage
	action="writetobrowser"
	source="#objImage#"
	/>

For Cut-and-Paste