Adobe COLDFUSION 9 Manual page 969

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Working with Documents, Charts, and Reports
Creating an image from a Base64 string
Base64 is a way to describe binary data as a string of ASCII characters. Some databases store images in Base64 format
rather than as BLOB data. You can use the
from a database. Doing so eliminates the intermediary steps of binary encoding and decoding.
The following examples show how to use the
<!--- This example shows how to create a ColdFusion image from a Base64 string with headers
(used for display in HTML). --->
<cfimage source="data:image/jpg;base64,/9j/4AAQSkZJRgABAQA.............."
destination="test_my64.jpeg" action="write" isBase64="yes">
<!--- This example shows how to use the cfimage tag to write a Base64 string without headers.
--->
<cfimage source="/9j/4AAQSkZJRgABAQA.............." destination="test_my64.jpeg"
action="write" isBase64="yes">
The following examples show how to use the
string:
<!--- This example shows how to use the ImageReadBase64 function to read a Base64 string
with headers. --->
<cfset myImage=ImageReadBase64("data:image/jpg;base64,/9j/4AAQSkZJRgABAQA..............")>
<!--- This example shows how to read a Base64 string without headers. --->
<cfset myImage=ImageReadBase64("/9j/4AAQSkZJRgABAQA..............")>
For more information on Base64 strings, see
Copying an image
You use the
function to copy a rectangular area of an existing image and generate a new ColdFusion image
ImageCopy
from it. You can paste the new ColdFusion image onto another image, or write it to a file, as the following example
shows:
<!--- Use the cfimage tag to create a ColdFusion image from a JPEG file.
--->
<cfimage source="../cfdocs/images/artgallery/lori05.jpg" name="myImage">
<!--- Turn on antialiasing to improve image quality. --->
<cfset ImageSetAntialiasing(myImage)>
<!--- Copy the rectangular area specified by the coordinates (25,25,50,50) in the image to
the rectangle beginning at (75,75), and return this copied rectangle as a new ColdFusion
image. --->
<cfset dupArea = ImageCopy(myImage,25,25,50,50,75,75)>
<!--- Write the new ColdFusion image (dupArea) to a PNG file. --->
<cfimage source="#dupArea#" action="write" destination="test_myImage.png" overwrite="yes">
Duplicating an image
Another way to create a ColdFusion image is to duplicate it. Duplicating an image creates a clone, which is a copy of
an image that is independent of it: if the original image changes, those changes do not affect the clone, and the reverse.
This technique is useful if you want to create several versions of the same image. Duplicating an image can improve
processing time because you retrieve image data from a database or a file once to create the ColdFusion image. Then
you can create several clones and manipulate them in memory before writing them to files. For example, you could
create a thumbnail version, a grayscale version, and an enlarged version of an image uploaded to a server. To do so,
you use the
tag or the
cfimage
function to create three clones of the ColdFusion image.
Duplicate
tag or the
cfimage
tag to create a ColdFusion image from a Base64 string:
cfimage
ImageReadBase64
"Converting an image to a Base64
function to create a ColdFusion image from the uploaded file. You use the
ImageNew
Last updated 8/5/2010
function to read Base64 data directly
ImageReadBase64
function to create a ColdFusion image from a Base64
string" on page 966.
964

Advertisement

Table of Contents
loading

Table of Contents