Adobe ColdFusion 8

Creating a CAPTCHA image

You use the captcha action of the cfimage tag to create a distorted text image that is human-readable but not machine-readable. When you create a CAPTCHA image, you specify the text that is displayed in the CAPTCHA image; ColdFusion randomly distorts the text. You can specify the height and width of the text area, which affects the spacing between letters, the font size, the fonts to use for the CAPTCHA text, and the level of difficulty, which affects readability. Do not use spaces in the text string specified for the text attribute: users cannot detect the spaces as part of the CAPTCHA image.

The following example shows how to write a CAPTCHA image directly to the browser.

<!--- This example shows how to create a CAPTCHA image with the text "rEadMe" and write the
    image directly to the browser. --->
<cfimage action="captcha" fontSize="25" width="162" height="75" text="rEadMe"
    fonts="Verdana,Arial,Courier New,Courier">

Note: For the CAPTCHA image to display, the width value must be greater than: fontSize times the number of characters specified in text times 1.08. In this example, the minimum width is 162.

ColdFusion 8 supports CAPTCHA images in PNG format only.

Note: If you specify the destination attribute to write CAPTCHA images to files, use unique names for the CAPTCHA image files so that when multiple users access the CAPTCHA images, the files are not overwritten.

The following example shows how to create CAPTCHA images with a high level of text distortion.

<!--- Use the GetTickCount function to generate unique names for the CAPTCHA files. --->
<cfset tc = GetTickCount()>
<!--- Set the difficulty to "high" for a higher level of text distortion. --->
<cfimage action="captcha" fontSize="15" width="180" height="50" text="rEadMe"
    destination="readme#tc#.png" difficulty="high">

For a detailed example, see Using CAPTCHA to verify membership.

The following image shows three CAPTCHA images with low, medium, and high levels of difficulty, respectively: