<cffunction
name="EasyCaptcha"
access="public"
returntype="array"
output="true"
hint="Outputs a CAPTCHA problem using a series of images rather than one image.">
<cfargument
name="Text"
type="string"
required="true"
hint="The text that will be output in the CAPTCHA."
/>
<cfargument
name="FontSize"
type="string"
required="false"
default="20"
hint="The font size to use for the CAPTCHA."
/>
<cfargument
name="BackgroundColor"
type="string"
required="false"
default="##FAFAFA"
hint="The canvas color."
/>
<cfargument
name="Color"
type="string"
required="false"
default="##333333"
hint="The drawing (Text) color."
/>
<cfset var LOCAL = {} />
<cfset LOCAL.FontProperties = {
Font = "Courier New",
Size = ToString( ARGUMENTS.FontSize ),
Style = "normal"
} />
<cfset LOCAL.Images = [] />
<cfloop
index="LOCAL.CharacterIndex"
from="1"
to="#Len( ARGUMENTS.Text )#"
step="1">
<cfset LOCAL.Character = Mid(
ARGUMENTS.Text,
LOCAL.CharacterIndex,
1
) />
<cfset LOCAL.Dimensions = THIS.GetTextDimensions(
LOCAL.Character,
LOCAL.FontProperties
) />
<cfset LOCAL.Image = ImageNew(
"",
(LOCAL.Dimensions.Width + 6),
Ceiling( LOCAL.Dimensions.Height * 1.5 ),
"rgb",
ARGUMENTS.BackgroundColor
) />
<cfset ImageSetDrawingColor(
LOCAL.Image,
ARGUMENTS.Color
) />
<cfset ImageDrawText(
LOCAL.Image,
LOCAL.Character,
3,
Ceiling( LOCAL.Dimensions.Height * 1.1 ),
LOCAL.FontProperties
) />
<cfset ArrayAppend(
LOCAL.Images,
LOCAL.Image
) />
</cfloop>
<cfsavecontent variable="LOCAL.Buffer">
<cfloop
index="LOCAL.Image"
array="#LOCAL.Images#">
<cfimage
action="writetobrowser"
source="#LOCAL.Image#"
format="gif"
/>
</cfloop>
</cfsavecontent>
<cfset LOCAL.Buffer = Trim(
REReplace(
LOCAL.Buffer,
"\s+(?=<)",
"",
"all"
)
) />
<cfset WriteOutput( LOCAL.Buffer ) />
<cfreturn LOCAL.Images />
</cffunction>