How can I create a CAPTCHA image with ColdFusion?

CAPTCHA images contain distorted text that is human-readable but not machine-readable.

The <cfimage> tag allows you to create CAPTCHA images. You can specify the text you want to distort, the height and width of the text area, font and font size, and the level of difficulty (affects readability).

Note: As per the ColdFusion docs, in order 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.

<!--- font size = 25, number of characters = 11, then required number 1.08 --->
<cfset size = 25 * 11 * 1.08/>
<cfimage action="captcha" fontSize="25" width="#size#" height="50"
text="ThisIsATest" fonts="Verdana,Arial,Courier New,Courier" difficulty="low">

This question was written by Jeremy Petersen
It was last updated on December 6, 2007.


Display and Layout


comments powered by Disqus