Re: How to create an Captcha with TclMagick?



Einstein30000 wrote:
to protect my self-made board against Spambots a captcha is necessary.
So i have to create one using TclMagick.
Dominic

I have a TCL script which demonstrates generation of a captcha. It uses
a fixed string but that, and some other features of the script, can easily be randomized.

Hope this helps.
Pete (to reply: NN = 01)




# Demo to generate a captcha
package require TclMagick
set m [magick create wand]
set n [magick create wand]
set d [magick create draw]
set p [magick create pixel]

# Create a large white canvas to give lots of room for the text
# Later on it will be trimmed down
$p color white
$m new 640 640 $p

# Now select the font and set its colour and size
$p color red
$d fillcolor $p
$d font Times-New-Roman
$d fontsize 24

# and annotate the image *without* any rotation
$m annotate $d 100 100 0 "Z R B Y A"

# Trim the image to remove all the excess surrounding the text
$m trim
# Now mangle it a bit. The values for swirl and wave should be randomized
$m swirl 20
$m wave 4 50
# Get the size of the current image
set w [$m width]
set h [$m height]
# increase the width and height to allow for a border around the text
incr w 10
incr h 6
# Create a new white image
$p color white
$n new $w $h $p
# Add noise to it
$n addnoise Gaussian
# Composite the text image on the noise image
# The coordinate for the composite should be half the border dimensions
# so that the text image is centred over the noise image
$n composite $m Multiply 5 3
# And save the image
$n write test.jpg
# Clean up
magick delete $m $d $p $n




.