cfimage

Creates a ColdFusion image that can be manipulated by using image functions.
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.

  <cfimage>

 cfimage();

Attribute Reference

action string
Default: read

The action to take.
Values:
  • border
  • captcha
  • convert
  • info
  • read
  • resize
  • rotate
  • write
  • writeToBrowser

angle numeric

Angle in degrees to rotate the image.

color string

(border) Border color.
Hexadecimal value or supported named color.
For a hexadecimal value, use the form "##xxxxxx" or "xxxxxx". (required)

destination string

Absolute or relative pathname where the image output is written.
The image format is determined by the file extension.
The convert and write actions require a destination.
The border, captcha, resize, and rotate actions require either a name attribute or a destination attribute.
You can specify both.
Scorpio supports only CAPTCHA images in PNG format.
If you do not enter a destination, the CAPTCHA image is placed inline in the HTML output and displayed in the web browser.

difficulty string
Default: low

Level of complexity of the CAPTCHA text.
Values:
  • high
  • medium
  • low

fontSize numeric

Font size of the text in the CAPTCHA image.
The value must be an integer.

format string

Format of the image displayed in the browser.
If you do not specify a format, the image is displayed in PNG format.
You cannot display a GIF image in a browser.
GIF images are displayed in PNG format.
Values:
  • png
  • jpg
  • jpeg

height numeric

Height in pixels of the image.
For the resize attribute, you also can specify the height as a percentage (an integer followed by the "%" symbol).
The value must be an integer.

isBase64 boolean
Default: false

Specifies whether the source is a Base64 string or not.
Values:
  • true
  • false

name string

Name of the ColdFusion image variable to create.
The read action requires name attribute.
The border, resize, and rotate options require a name attribute or a destination attribute.
You can specify both.

overwrite boolean
Default: false

Valid only if the destination attribute is specified.
If the destination file already exists, ColdFusion generates an error if the overwrite option is not set to yes.
Values:
  • true
  • false

quality numeric
Default: 0.75

Quality of the JPEG destination file.
Applies only to files with an extension of JPG or JPEG.
Valid values are fractions that range from 0 through 1
(the lower the number, the lower the quality).

source any

URL of the source image; for example, "http://www.google.com/ images/logo.gif"
Absolute or relative pathname of the source image; for example, "c:\wwwroot\images\logo.jpg"
ColdFusion image variable containing another image, BLOB, or byte array; for example, "#myImage#"
Base64 string; for example, "data:image/jpg;base64,/9j/ 4AAQSkZJRgABAQA.............."

structName string

Name of the ColdFusion structure to be created.

text string

Text string displayed in the CAPTCHA image.
Use capital letters for better readability.

thickness numeric
Default: 1

Border thickness in pixels.
The border is added to the outside edge of the source image,
increasing the image area accordingly.
The value must be an integer.

width string

Width in pixels of the image.
For resize, you also can specify the width as a percentage
(an integer followed by the "%" symbol).
The value must be an integer.

fonts string

One or more valid fonts to use for the CAPTCHA text. Separate multiple fonts with commas. ColdFusion supports only the system fonts that the JDK can recognize.

interpolation string
Default: highestQuality

CF 10+ Used when action=resize determines the interpolation algorithm to use.
Values:
  • highestQuality
  • highQuality
  • mediumQuality
  • highestPerformance
  • highPerformance
  • mediumPerformance
  • nearest
  • bilinear
  • bicubic
  • bessel
  • blackman
  • hamming
  • hanning
  • hermite
  • lanczos
  • mitchell
  • quadratic

Links more information about cfimage

Examples
Sample code using the cfimage tag

Add a red border of 5 pixels to an image, write the output to a variable.

<cfimage action="border" source="#sourceImage#" size=5 color="red" name="withborder">

Generate a CAPTCHA style image using medium difficulty.

<cfimage action="captcha" width="200" height="50" text="Captcha!" difficulty="medium" fontSize="18" fonts="Comic Sans MS,Times New Roman">

Convert an image to a different format (in this case PNG).

<cfimage action="convert" source="#sourceImage#" destination="#expandPath( 'destination.png' )#" overwrite="true">

Retrieve meta data from an image and stores that as a structure in a variable.

<cfimage action="info" source="http://lorempixel.com/60/50/" structname="imageInfo">
<cfdump var="#imageInfo#">

Tag syntax for reading an image from a URL.

<cfimage action="read" name="sourceImage" source="http://lorempixel.com/60/50/">

Example of resizing an image stored in a variable and storing the result in a variable.

<cfimage action="resize" source="#sourceImage#" height="200" width="200" name="resized">

Rotate an image 30 degrees clockwise.

<cfimage action="rotate" source="#sourceImage#" destination="#expandPath( 'rotated.jpg' )#" overwrite="true" angle="30" quality="1">

Example of writing an image as an 80% compressed jpg image.

<cfimage action="write" source="#sourceImage#" destination="#expandPath( 'newImage.jpg' )#" overwrite="true" quality=".2">

Generates HTML to output the image in place.

<cfimage action="writeToBrowser" source="#sourceImage#">

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub