Home Tutorials/How to Links Blog Photos

Using CFIMAGE to create a watermark

Continuing my week off playing around with cfimage, I am thinking this is fast becoming my favorite new feature in Coldfusion 8. This morning I was thinking it would be cool if Coldfusion could watermark images for me. After about 30mins playing around I came up with this.

<cfimage source="img_2566.jpg" name="image">
<cfimage source="watermark.png" name="watermark">
<cfset ImagePaste(image, watermark, 0, 0)>
<cfimage source="#image#" action="writeToBrowser" format="jpg">
First 2 lines I basically give both images a name. The reason the watermark is a png is I want to have the ability to use alpha channels. Next line I paste the watermark onto the image at 0x and 0y. I cheated and created the images the same size, but you could easily read the image info get the size then calculate where you want the watermark to be. The last line writes the image to the browser in the format of a jpeg. You can check it out in action at my CFwatermark page.

Comments
Damon Ledet's Gravatar After looking at this some more I could not find a way to do ALT text for my image when writing to the browser.

by using <cfsavecontent> however here is a little trick

<cfsavecontent variable="imagewithalt"><cfimage source="#image#" action="writeToBrowser" format="jpg" ></cfsavecontent>
<cfoutput>#Replace(imagewithalt, 'alt=""', 'alt="Watermark created on the fly by cfimage tag Coldfusion 8"')#</cfoutput>
# Posted By Damon Ledet | 11/21/07 3:03 PM