ImageDrawText

Description

Draws a text string on a ColdFusion image with the baseline of the first character positioned at (x,y) in the image.

Returns

Nothing.

Function syntax

ImageDrawText(name, str, x, y [, attributeCollection])

History

ColdFusion 8: Added this function.

Parameters

Parameter

Description

name

Required. The ColdFusion image on which this operation is performed.

str

Required. The text string to draw.

x

Required. The x coordinate for the start point of the string.

y

Required. The y coordinate for the start point of the string.

attributeCollection

Optional. The structure used to specify the text characteristics. See the Usage section.

Usage

Specify all the optional key-value pairs in an attributeCollection structure. To specify the text color, use the ImageSetDrawingColor function.

attributeCollection

Element

Description

font

The name of the font used to draw the text string. If you do not specify the font attribute, the text is drawn in the default system font.

size

The font size for the text string. The default value is 10 points.

style

The style to apply to the font:

  • bold

  • italic

  • boldItalic

  • plain (default)

strikethrough

Specify whether strikethrough is applied to the text image:

  • yes: For vertical text, strikethrough is applied to each character individually.

  • no (default)

underline

Specify whether underline is applied to the text image:

  • yes: For vertical text, underline is applied to each character individually.

  • no (default)

Example

Example 1

<!--- This example shows how to create a text string image. ---> 
<!--- Use the ImageNew function to create a 200x100-pixel image. ---> 
<cfset myImage=ImageNew("",200,100)> 
<!--- Set the drawing color to green. ---> 
<cfset ImageSetDrawingColor(myImage,"green")> 
<!--- Specify the text string and the start point for the text. ---> 
<cfset ImageDrawText(myImage,"It's not easy being green.",10,50)> 
<!--- Display the image in a browser. ---> 
<cfimage source="#myImage#" action="writeToBrowser">

Example 2

<!--- This example shows how to draw three text strings with different text attributes. ---> 
<!--- Use the ImageNew function to create a 400x400-pixel image. ---> 
<cfset myImage=ImageNew("",400,400)> 
<!--- Set the text attributes. ---> 
<cfset attr = StructNew()> 
<cfset attr.underline = "yes"> 
<cfset attr.size = 25> 
<cfset attr.style = "bold"> 
<cfset ImageSetDrawingColor(myImage,"yellow")> 
<!--- Draw the text string "ColdFusion Rocks!" starting at (100,150). ---> 
<cfset ImageDrawText(myImage,"ColdFusion Rocks!",100,150,attr)>  
<!--- Set new text attributes. ---> 
<cfset attr=StructNew()> 
<cfset attr.size = 18> 
<cfset attr.strikethrough = "yes"> 
<cfset attr.style = "bolditalic"> 
<cfset ImageSetDrawingColor(myImage,"red")> 
<!--- Draw the text string "Powered by ColdFusion" starting at (100,200).  
    ---> 
<cfset ImageDrawText(myImage,"Powered by ColdFusion",110,200,attr)>  
<!--- Set new text attributes. ---> 
<cfset attr = StructNew()> 
<cfset attr.font="Arial"> 
<cfset attr.style="italic"> 
<cfset attr.size=15> 
<cfset ImageSetDrawingColor(myImage,"white")> 
<!--- Draw the text string "Coming in 2007" starting at (150,250). ---> 
<cfset ImageDrawText(myImage,"We've arrived",150,250,attr)>  
<!--- Display the text image in a browser. ---> 
<cfimage source="#myImage#" action="writeToBrowser">