Adobe COLDFUSION 9 Manual page 980

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Working with Documents, Charts, and Reports
<!--- This example shows how to draw a red circle with a line through it and use it as a
watermark. --->
<!--- Use the ImageNew function to create a ColdFusion image that is 201x201 pixels. --->
<cfset myImage=ImageNew("",201,201)>
<!--- Set the drawing transparency of the image to 30%. --->
<cfset ImageSetDrawingTransparency(myImage,30)>
<!--- Set the drawing color to red. --->
<cfset ImageSetDrawingColor(myImage,"red")>
<!--- Create an attribute collection that sets the line width to ten pixels. --->
<cfset attr=StructNew()>
<cfset attr.width = 10>
<!--- Apply the attribute collection to the ImageSetDrawingStroke function. --->
<cfset ImageSetDrawingStroke(myImage,attr)>
<!--- Draw a diagonal line starting at (40,40) and ending at (165,165) on myImage. The drawing
attributes you specified are applied to the line. --->
<cfset ImageDrawLine(myImage,40,40,165,165)>
<!--- Draw a circle starting at (5,5) and is 190 pixels high and 190 pixels wide. The drawing
attributes you specified are applied to the oval. --->
<cfset ImageDrawOval(myImage,5,5,190,190)>
<!--- Create a ColdFusion image from a JPEG file. --->
<cfimage source="../cfdocs/images/artgallery/raquel05.jpg" name="myImage2">
<!--- Scale the image to fit in a 200-pixel square, maintaining the aspect ratio of the
source image. --->
<cfset ImageScaleToFit(myImage2,200,200)>
<!--- Paste the myImage2 directly over the myImage. --->
<cfset ImagePaste(myImage,myImage2,0,0)>
<!--- Save the combined image to a file. --->
<cfimage source="#myImage#" action="write" destination="test_watermark.jpg" overwrite="yes">
<!--- Display the image in a browser. --->
<img src="test_watermark.jpg"/>
Writing images to the browser
Use the
action of the
writeToBrowser
files. This technique is useful for testing the appearance of a ColdFusion image. The following example shows how to
test the display of two effects applied to an image:
<cfset myImage=ImageNew("../cfdocs/images/artgallery/paul01.jpg")>
<cfset ImageBlur(myImage,5)>
<cfset ImageNegative(myImage)>
<cfimage source="#myImage#" action="writeToBrowser">
The
action displays images in PNG format.
writeToBrowser
Also, you can write multiple images to the browser which is useful if you want to manipulate images in memory and
display them without writing them to files. For example, you can duplicate several versions of the same image, display
the versions in a browser, and allow the user to choose one of the images to write to a file. Or, you can extract images
from a database, add a watermark to the images that appear in the browser, such as Proof or Draft, without having to
write the modified images to files first. This way you can maintain one set of image files and change them on-the-fly.
For an example of writing multiple images to the browser, see
page 977.
Application examples that use ColdFusion images
You can create simple applications that automate image processes by using ColdFusion images.
tag to display images directly in the browser without writing them to
cfimage
"Generating a gallery of watermarked
Last updated 8/5/2010
975
images" on

Advertisement

Table of Contents
loading

Table of Contents