ImageGetBlob

Description

Retrieves the bytes of the underlying image. The bytes are in the same image format as the source image.

Returns

The bytes of the underlying image of a BLOB.

Function syntax

ImageGetBlob(source)

History

ColdFusion 8: Added this function.

Parameters

Parameter

Description

source

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

Usage

Use this function to insert ColdFusion images into BLOB columns of databases.

If you do not specify a source image, you get a parameter validation error.

Example

Example 1

<!--- This example shows how to add a ColdFusion image to a database. ---> 
<!--- Create ColdFusion image from a 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>

Example 2

The following example shows how to use the ImageNew function to generate thumbnail images in JPEG format from BLOB data retrieved from a database:

<!--- 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 image 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 a 100x100-pixel image, while maintaining the aspect ratio of the  
    source image. ---> 
<cfset ImageScaleToFit(myImage,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">