Adobe ColdFusion 8

ImageWriteBase64

Description

Writes Base64 images to the specified filename and destination.

Returns

Base64 string.

Category

Image functions

Function syntax

ImageWriteBase64(name, destination, format [, inHTMLFormat])

See also

cfimage, ImageReadBase64, IsImageFile

History

ColdFusion 8: Added this function.

Parameters

Parameter

Description

name

Required. The ColdFusion image on which this operation is performed.

destination

Required. The absolute or relative pathname where you write the file.

format

Required. The format

inHTMLFormat

Optional. Specify whether Base64 output includes the headers used by the Base64 images in the HTML <img> tag ("data:image/<format>;base64,...") :

  • yes
  • no (default)

Usage

You use the ImageWriteBase64 function to encode image data as a string of printable characters. This is useful for several applications,including sending images by e-mail and storing images in database text fields.

If you do not specify a file format, ColdFusion cannot recognize the format required to encode the image before converting to Base64, and generates errors.

You can verify whether ColdFusion reads a Base64 string properly in the following ways:

  • Use the cfdump tag. For example: <cfdump var="#myImage#">
  • Use the ImageInfo function. For example: <cfset ImageInfo(myImage)>
  • Use the ImageWrite function and save the image as a JPEG file. Then open the JPEG file in a browser or imaging application.

Example

<!--- This example shows how to convert a JPEG image to Base64 format and save it to a file. --->
<!--- Create a new ColdFusion image. --->
<cfset myImage=ImageNew("../cfdocs/images/artgallery/jeff01.jpg")>
<!--- Convert the image to Base64 format and write it to a file.--->
<cfset ImageWriteBase64(myImage,"jeffBase64.txt","jpg","yes")>