Adobe ColdFusion 8

Creating a watermark from a text image

The following example shows how to create a text image in ColdFusion and use it as a watermark:

<!--- Create a ColdFusion image from an existing JPG file. --->
<cfset myImage=ImageNew("../cfdocs/images/artgallery/raquel05.jpg")>
<!--- Scale the image to fit in a 200-pixel square, maintaining the aspect ratio of the
    source image. --->
    <cfset ImageScaleToFit(myImage,200,200)>
<!--- Set the drawing transparency to 75%. --->
    <cfset ImageSetDrawingTransparency(myImage,75)>
<!--- Create a ColdFusion image from scratch. --->
<cfset textImage=ImageNew("",150,140)>
<!--- Set the drawing color to white. --->
    <cfset ImageSetDrawingColor(textImage,"white")>
<!--- Create a collection of text attributes. --->
        <cfset attr=StructNew()>
        <cfset attr.size=40>
        <cfset attr.style="bold">
        <cfset attr.font="Arial">
<!--- Turn on antialiasing. --->
<cfset ImageSetAntialiasing(textImage)>
<!--- Draw the text string "PROOF" on the ColdFusion image. Apply the text attributes that
    you specified. --->
<cfset ImageDrawText(textImage,"PROOF",1,75,attr)>
<!--- Rotate the text image by 30 degrees. --->
    <cfset ImageRotate(textImage,30)>
<!--- Scale the image to fit in a 200-pixel square, maintaining the aspect ratio of the
    source image. --->
    <cfset ImageScaleToFit(textImage,200,200)>
<!--- Paste the text image onto myImage. --->
<cfset ImagePaste(myImage,textImage,0,0)>
<!--- Write the combined image to a file. --->
<cfimage source="#myImage#" action="write" destination="test_watermark.jpg" overwrite="yes">
<!--- Display the image. --->
<img src="test_watermark.jpg"/>