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)

Argument Reference

name string
Required

The image on which this operation is performed.

str string
Required

The text to draw.

x numeric
Required

The x coordinate for the start point of the string.

y numeric
Required

The y coordinate for the start point of the string.

attributecollection struct

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

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

CF 11+ Lucee 4.5+ Create a 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);

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub