cfimage

Description

Creates a ColdFusion image. You can use the cfimage tag to perform common image manipulation operations as a shortcut to Image functions. You can use the cfimage tag independently or in conjunction with Image functions.

Categories

Related

History

ColdFusion 8: Added this tag.

Syntax

Add a border to an image  
<cfimage 
    required  
    action = "border" 
    source = "absolute pathname|pathname relative to the web root|URL|#cfimage variable#" 
    optional 
    color = "hexadecimal value|web color" 
    destination = "absolute pathname|pathname relative to the web root" 
    isBase64 = "yes|no" 
    name = "cfimage variable" 
    overwrite = "yes|no" 
    thickness = "number of pixels"> 
 
Create a CAPTCHA image 
<cfimage 
    required 
    action = "captcha" 
    height = "number of pixels" 
    text = "text string" 
    width = "number of pixels" 
    optional 
    destination = "absolute pathname|pathname relative to the web root" 
    difficulty = "high|medium|low" 
    overwrite = "yes|no" 
    fonts = "comma-separated list of font names" 
    fontSize = "point size"> 
 
Convert an image file format 
<cfimage 
    required 
    action = "convert" 
    destination = "absolute pathname|pathname relative to the web root" 
    source = "absolute pathname|pathname relative to the web root"|URL|#cfimage variable# 
    optional 
    isBase64 = "yes|no" 
    name = "cfimage variable" 
    overwrite = "yes|no"> 
 
Retrieve information about an image 
<cfimage 
    required 
    action = "info" 
    source = "absolute pathname|pathname relative to the web root|URL|#cfimage variable#" 
    structname = "structure name" 
    optional 
    isBase64 = "yes|no"> 
 
Read an image into memory 
<cfimage 
    required 
    name = "cfimage variable" 
    source = "absolute pathname|pathname relative to the web root|URL|#cfimage variable#" 
    optional 
    action = "read" 
    isBase64 = "yes|no"> 
 
Resize an image 
<cfimage 
    required 
    action = "resize" 
    height = "number of pixels|percent%" 
    source = "absolute pathname|pathname relative to the web root|URL|#cfimage variable#" 
    width = "number of pixels|percent%" 
    optional 
    destination = "absolute pathname|pathname relative to the web root" 
    isBase64 = "yes|no" 
    name = "cfimage variable" 
    overwrite = "yes|no"> 
 
Rotate an image 
<cfimage 
    required 
    action = "rotate" 
    angle = "angle in degrees" 
    source = "absolute pathname|pathname relative to the web root|URL|#cfimage variable#" 
    optional 
    destination = "absolute pathname|pathname relative to the web root" 
    isBase64= "yes|no" 
    name = "cfimage variable" 
    overwrite = "yes|no"> 
 
Write an image to a file 
<cfimage 
    required 
    action = "write" 
    destination = "absolute pathname|pathname relative to the web root" 
    source = "absolute or relative pathname|URL|#cfimage variable#" 
    optional 
    isBase64= "yes|no" 
    overwrite = "yes|no" 
    quality = "JPEG image quality"> 
 
Write an image to the browser 
<cfimage 
    required 
    action = "writeToBrowser" 
    source = "absolute pathname|pathname relative to the web root|URL|#cfimage variable#" 
    optional 
    format = "png|jpg|jpeg" 
    isBase64= "yes|no">
Note: You can specify this tag’s attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag’s attribute names as structure keys.

Attributes

AttributeDescriptionRequiredDefault
actionN/A
anglerotate
colorborder
destinationborder captcha convert resize rotate write
difficultycaptcha
fontscaptcha
fontSizecaptcha
formatwriteToBrowser
heightcaptcha resize
isBase64border convert info read resize rotate write writeToBrowser
nameborder convert read resize rotate
overwriteborder captcha convert read resize rotate write
qualitywrite
sourceborder convert info read resize rotate write writeToBrowser
structNameinfo
textcaptcha
thicknessborder
widthcaptcha resize

Usage

ColdFusion provides the cfimage tag and the ColdFusion image, a construct native to ColdFusion that contains image data. You can manipulate ColdFusion images in memory and write them to a file, a database, or directly to a browser. You use the cfimage tag to create ColdFusion images from existing image files and perform simple image actions, such as rotating or resizing. Alternatively, you can use the ImageNew function to create a ColdFusion image from the beginning or from an existing image. You can use the Image functions to perform complex image manipulation operations on ColdFusion images that you create with the cfimage tag or with the ImageNew function.
You can perform the following tasks with ColdFusion images:
Convert an image from one file format to another. For example, you can convert a BMP file to a JPEG file or a Base64 string to a GIF.
Enforce consistent sizes on files uploaded to the server.
Enforce size limits on JPEG images (by changing the quality of the image).
Save a ColdFusion image to a file or write the image directly to a browser.
Use the ImageGetBlob function within the cfquery tag to insert a ColdFusion image as a Binary Large Object Bitmap (BLOB) in a database. Also, you can extract a BLOB from a database and generate a ColdFusion image from it.
Create watermark images.
Create thumbnail images.
Create a Completely Automated Public Turing test to tell Computers and Humans Apart (CAPTCHA) image, a distorted text image that is human-readable, but not machine-readable, used in a challenge-response test for preventing spam.
For more detailed examples, see Creating and Manipulating ColdFusion Images in the Developing ColdFusion Applications.

Example

This example shows how to create a ColdFusion image and manipulate it by using Image functions:
<!--- Create the ColdFusion image variable "myImage" from a JPEG file. ---> 
<cfimage source="../cfdocs/images/artgallery/jeff05.jpg" name="myImage"> 
<!--- Pass the ColdFusion image to the Image functions to blur the image by a radius of 5, 
    flip the image 90 degrees, and convert the image to grayscale. ---> 
<cfset ImageBlur(myImage,5)> 
<cfset ImageFlip(myImage,"90")> 
<cfset ImageGrayscale(myImage)> 
<!--- Write the transformed image to a browser. ---> 
<cfimage source="#myImage#" action="writeToBrowser">