Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 971

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
<cfimage source="../cfdocs/images/artgallery/jeff01.jpg" action="convert"
destination="jeff01.gif" name="myImage">
ColdFusion reads and writes most standard image formats. For more information, see Supported image file formats
in the CFML Reference.
Converting an image to a Base64 string
To convert a ColdFusion image to a Base64 string, use the ImageWriteBase64 function. In the following example, the
value determines that the output includes the headers required for display in HTML:
yes
<!--- This example shows how convert a BMP file to a Base64 string. --->
<cfset ImageWriteBase64(myImage,"jeffBase64.txt","bmp","yes")>
Note: Microsoft Internet Explorer does not support Base64 strings.
Inserting an image as a BLOB in a database
Many databases store images as BLOB data. To insert a ColdFusion image into a BLOB column of a database, use the
ImageGetBlob function within a
<!--- This example shows how to add a ColdFusion image to a BLOB column of a database. --->
<!--- Create a ColdFusion image from an existing JPEG file. --->
<cfimage source="aiden01.jpg" name="myImage">
<!--- Use the cfquery tag to insert the ColdFusion image as a BLOB in the database. --->
<cfquery name="InsertBlobImage" datasource="myBlobData">
INSERT into EMPLOYEES (FirstName,LastName,Photo)
VALUES ("Aiden","Quinn",<cfqueryparam value="#ImageGetBlob(myImage)#"
cfsqltype="cf_sql_blob">)
</cfquery>
Verifying images
Use the
function to test whether an image variable represents a valid ColdFusion image. This function takes
IsImage
a variable name as its only parameter and returns a Boolean value.
Note: You cannot use the
IsImage
function.
Also, ColdFusion provides two tags for determining which image file formats are supported on the server where the
ColdFusion application is deployed: GetReadableImageFormats and GetWriteableImageFormats. For more
information, see the CFML Reference.
Enforcing size restrictions
ColdFusion provides several functions for retrieving information associated with images, including the height and
width of an image. For example, you can use the
whether an image is too large to upload to a website or database.
The following example shows how to prevent users from uploading images that are greater than 300 pixels wide or 300
pixels high:
statement, as the following example shows:
cfquery
function to verify whether files are valid images. Instead, use the
ImageGetWidth
Last updated 1/20/2012
and
functions to determine
ImageGetHeight
966
IsImageFile

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents