Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 975

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Working with Documents, Charts, and Reports
...
<cfset ImageDrawText(myImage,"Congratulations!",10,50,attr)>
To change the color of the text, use the
subsequent drawing objects on an image. In the following example, two lines of text, "Congratulations!" and
"Gabriella", inherit the color magenta.
<!--- This example shows how to draw a text string on a blank image. --->
<cfset myImage=ImageNew("../cfdocs/images/artgallery/jeff01.jpg")>
<cfset ImageSetDrawingColor(myImage,"magenta")>
<cfset attr = StructNew()>
<cfset attr.style="bolditalic">
<cfset attr.size=20>
<cfset attr.font="verdana">
<cfset attr.underline="yes">
<cfset ImageDrawText(myImage,"Congratulations!",10,50,attr)>
<cfset ImageDrawText(myImage,"Gabriella",50,125,attr)>
<cfimage source="#myImage#" action="write" destination="myImage.jpg" overwrite="yes">
<img src="myImage.jpg"/>
For a list of valid named colors, see the cfimage tag in the CFML Reference.
Drawing lines and shapes
ColdFusion provides several functions for drawing lines and shapes. For shapes, the first two values represent the x
and y coordinates, respectively, of the upper-left corner of the shape. For simple ovals and rectangles, the two numbers
following the coordinates represent the width and height of the shape in pixels. For a line, the values represent the x
and y coordinates of the start point and end point of the line, respectively. To create filled shapes, set the
attribute to true. The following example shows how to create an image with several drawing objects:
<!--- Create an image that is 200-pixels square. --->
<cfset myImage=ImageNew("",200,200)>
<!--- Draw a circle that is 100 pixels in diameter. --->
<cfset ImageDrawOval(myImage,40,20,100,100)>
<!--- Draw a filled rectangle that is 40 pixels wide and 20 pixels high.
--->
<cfset ImageDrawRect(myImage,70,50,40,20,true)>
<!--- Draw a 100-pixel square. --->
<cfset ImageDrawRect(myImage,40,40,100,100)>
<!--- Draw two lines. --->
<cfset ImageDrawLine(myImage,130,40,100,200)>
<cfset ImageDrawLine(myImage,50,40,100,200)>
<!--- Write the ColdFusion image to a file. --->
<cfimage source="#myImage#" action="write" destination="testMyImage.gif" overwrite="yes">
<img src="testMyImage.gif"/>
Note: To draw a sequence of connected lines, use the
Reference.
Setting drawing controls
ColdFusion provides several functions for controlling the appearance of drawing objects. As shown in the
example, you use the
ImageDrawText
function also controls the color of lines and shapes. To control line attributes (other than color), use the
function. The
ImageSetDrawingStroke
attributes.
function. This function controls the color of all
ImageSetDrawingColor
ImageDrawLines
function to define the color of text in an image. This
ImageSetDrawingColor
ImageSetDrawingStroke
Last updated 1/20/2012
function. For more information, see the CFML
function uses a collection to define the line
970
filled

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents