imageDrawText

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

imageDrawText(name, str, x, y, attributecollection) → returns void

Member Function Syntax

someImage.drawText(str, x, y, attributecollection)

imageDrawText Argument Reference

name
Required

The image on which this operation is performed.

str
Required

The text 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

A structure used to specify the text characteristics. the following keys are supported:
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: a boolean that specify whether strikethrough is applied to the text image, default is false.
underline: a boolean that specify whether underline is applied to the text image, default is false.

Examples sample code invoking the imageDrawText function


Tag Syntax

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"> 

Using drawText member function

CF 11+ Lucee 4.5+ Create an new image. With the new image write "CFDocs" with the text characteristics specified

TextCharacteristics = { size="20", style="bold", strikethrough="false", underline="false"};
imgObj = imageNew("",152,152,"rgb","149c82");
imgObj.drawText("CFDocs",20,50,TextCharacteristics);
cfimage (action="writeToBrowser", source=imgObj);

Fork me on GitHub