
970
DEVELOPING
COLDFUSION 9 APPLICATIONS
Working with Documents, Charts, and Reports
Las
t
upda
te
d 8/5/2010
...
<cfset ImageDrawText(myImage,"Congratulations!",10,50,attr)>
To change the color of the text, use the
ImageSetDrawingColor
function. This function controls the color of all
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
filled
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
ImageDrawLines
function. For more information, see the CFML
Reference.
Setting drawing controls
ColdFusion provides several functions for controlling the appearance of drawing objects. As shown in the
ImageDrawText
example, you use the
ImageSetDrawingColor
function to define the color of text in an image. This
function also controls the color of lines and shapes. To control line attributes (other than color), use the
ImageSetDrawingStroke
function. The
ImageSetDrawingStroke
function uses a collection to define the line
attributes.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...