
967
DEVELOPING
COLDFUSION 9 APPLICATIONS
Working with Documents, Charts, and Reports
Las
t
upda
te
d 8/5/2010
<!--- Create a ColdFusion image named "myImage" from a file uploaded to the server. --->
<cfimage action="read" source="#fileUpload.serverFile#" name="myImage">
<!--- Determine whether the file is greater than 300 pixels in width or height. --->
<cfif ImageGetHeight(myImage) gt 300 or ImageGetWidth(myImage) gt 300>
<!--- If the file exceeds the size limits, delete it from the server. --->
<cffile action="delete" file="#fileUpload.serverDirectory#/#fileUpload.serverFile#">
<cfoutput>
<!--- Display the following message. --->
<p>
The image you uploaded was too big. It must be less than 300 pixels wide and 300 pixels
high. Your image was #imageGetWidth(myImage)# pixels wide and
#imageGetHeight(myImage)# pixels high.
</p>
</cfif>
For information about retrieving image metadata, see the ImageGetEXIFTag, ImageGetIPTCTag, and ImageInfo
functions in the
CFML Reference
.
Compressing JPEG images
To reduce the size of large files, you can convert a JPEG file to a lower quality image by using the
write
action of the
cfimage
tag. Specify a value between 0 (low) and 1 (high) for the
quality
attribute, as the following example shows:
<cfimage source="../cfdocs/images/artgallery/jeff05.jpg" action="write"
destination="jeff05_lq.jpg" quality="0.5" overwrite="yes">
You can perform the same operation by using the
ImageWrite
function:
<cfset myImage=ImageNew("jeff05.jpg")>
<cfset ImageWrite(myImage,"jeff05_lq.jpg","0.5")>
Manipulating ColdFusion images
You can perform a few common manipulation operations on ColdFusion images. For more information on
manipulating ColdFusion images, see the
CFML Reference
.
Adding borders to images
To create a simple border, use the
cfimage
tag. The following example creates a ColdFusion image with a 5-pixel blue
border:
<cfimage source="../cfdocs/images/artgallery/jeff01.jpg" action="border" thickness="5"
color="blue" destination="testMyImage.jpg" overwrite="yes">
<img src="testMyImage.jpg">
The border is added to the outside edge of the source image. This increases the area of the image.
To create complex borders, use the
ImageAddBorder
function. The following example shows how to nest borders:
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...