Adobe ColdFusion 8

ImageReadBase64

Description

Creates a ColdFusion image from a Base64 string.

Returns

A ColdFusion image.

Category

Image functions

Function syntax

ImageReadBase64(string)

See also

ImageNew, ImageRead, ImageWrite, ImageWriteBase64, BinaryDecode, BinaryEncode, IsImageFile

History

ColdFusion 8: Added this function.

Parameters

Parameter

Description

string

Required. The ColdFusion variable or Base64 string.

Usage

Base64 is a way to describe binary data as a printable string of characters. The ImageReadBase64 function takes Base64 strings as input and creates images from the strings.

The strings can be with or without the headers used to pass Base64 images to an HTML <img src> tag.

Use this function to convert any Base64 string to a ColdFusion image. Some databases store images as Base64 strings instead of BLOB data. You can query the database and use the ImageReadBase64 function to convert the string into a ColdFusion image. This eliminates the intermediary step of converting images with the BinaryEncode and BinaryDecode functions.

Really Simple Syndication (RSS) feeds transfer images in the form of embedded Base64 strings in the XML file. Use the ImageReadBase64 function to read these images in ColdFusion.

Example

Example 1

<!--- This example shows how to read a Base64 string with headers. --->

<cfset myImage = ImageReadBase64("data:image/jpg;base64,/9j/4AAQSkZJRgABAQA..............")>
<cfimage source="#myImage#" destination="test_my64.jpeg" action="write">

Example 2

<!--- This example shows how to read a Base64 string without headers. --->

<cfset myImage = ImageReadBase64("/9j/4AAQSkZJRgABAQA..............")>
<cfimage source="#myImage#" destination="test_my64.jpeg" action="write">