Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 968

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
<!--- Use the cffile tag to read an image file, convert it to binary format, and write the
result to a variable. --->
<cffile action = "readBinary" file = "jeff05.jpg" variable = "aBinaryObj">
<!--- Use the ImageNew function to create a ColdFusion image from the variable. --->
<cfset myImage=ImageNew(aBinaryObj)>
Creating images from BLOB data
Many databases store images as BLOB data. To extract BLOB data from a database, create a query with the
tag. The following example shows how to extract BLOB data and use the
format:
<!--- Use the cfquery tag to retrieve employee photos and last names from the database. --->
<cfquery
name="GetBLOBs" datasource="myblobdata">
SELECT LastName,Image
FROM Employees
</cfquery>
<cfset i = 0>
<table border=1>
<cfoutput query="GetBLOBs">
<tr>
<td>
#LastName#
</td>
<td>
<cfset i = i+1>
<!--- Use the cfimage tag to write the images to PNG files. --->
<cfimage source="#GetBLOBs.Image#" destination="employeeImage#i#.png"
action="write">
<img src="employeeImage#i#.png"/>
</td>
</tr>
</cfoutput>
</table>
The following example shows how to use the
<!--- Use the cfquery tag to retrieve all employee photos and employee IDs from a database. --->
<cfquery name="GetBLOBs" datasource="myBlobData">
SELECT EMLPOYEEID, PHOTO FROM Employees
</cfquery>
<!--- Use the ImageNew function to create a ColdFusion images from the BLOB data that was
retrieved from the database. --->
<cfset myImage = ImageNew(GetBLOBs.PHOTO)>
<!--- Create thumbnail versions of the images by resizing them to fit in a 100-pixel square,
while maintaining the aspect ratio of the source image. --->
<cfset ImageScaleToFit(myImage,100,100)>
<!--- Convert the images to JPEG format and save them to files in the thumbnails subdirectory,
using the employee ID as the filename. --->
<cfimage source="#myImage#" action="write"
destination="images/thumbnails/#GetBLOBs.EMPLOYEID#.jpg">
For information on converting a ColdFusion image to a BLOB, see
page 966.
function to generate ColdFusion images from BLOB data:
ImageNew
"Inserting an image as a BLOB in a
Last updated 1/20/2012
tag to write them to files in PNG
cfimage
963
cfquery
database" on

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents