Re: How to create an Captcha with TclMagick?



On Fri, 28 Sep 2007, Einstein30000 wrote:

Date: Fri, 28 Sep 2007 12:06:37 -0700
From: Einstein30000 <dominic_ernst@xxxxxx>
Newsgroups: comp.lang.tcl
Subject: How to create an Captcha with TclMagick?

Hi,

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

My current try on apache 1. Webserver (with installed rivet):

<?
package require TclMagick
set wand [magick create wand]
set draw [magick create drawing]
set rpx [magick create pixel red]
$rpx color red
$draw SetStrokeColor red
$draw SetFillColor red
$draw color 1 1 point
$wand SetSize 100 30
$wand DrawImage $draw
?>

This small script doesn't work and i can't understand the syntax of
TclMagick?! :-\


Einstein,

Actually, I posted some months back something you might find useful, and I'll repost it if it helps ... the first part is simple image manipulation, and the second addresses annotating images, which is, I believe what you are referring to (caption?) ...

The following snippet:

creates a photo image, creates a wand, reads a file into the wand,
and then copies the wand into the photo, stuffs the pic onto a label,
and then displays it ... Tclmagick allows you to create the images
dynamically, (rather than read them from files), and you can annotate
them, resize them etc. and then write them to a photo image, and display
Hope this helps ...

Cheers,
Rob Sciuk

-=-=-=-=-=

package require img::jpeg
package require TclMagick

set fil /mnt/home/rob/DogPen.jpg
set pic [image create photo]
set wnd [magick create wand]
$wnd read $fil
$pic put [$wnd writeblob]

set lbl [label .l -image $pic]
pack $lbl

-=-=-=-=-=

Also, when I went to figure out how to annotate images, it was a little
less than transparent (and I'm not talking about alpha channels here
necessarily), so you might find this code useful, I hope ...

proc drawWand { } {
return [magick create draw]
}
proc drawColour { colour } {
set pxl [magick create pixel]
$pxl SetColor $colour
return $pxl
}
proc annotate { wnd x y angle txt } {
set clr [qim::drawColour cyan ]
set drw [qim::drawWand]
$drw SetStrokeWidth 1.0
$drw SetStrokeColor $clr
$drw SetFillColor $clr
$drw SetStrokeOpacity .8
$drw SetFillOpacity .8
$drw SetFontSize 24
$drw rotate $angle
$drw Annotation $x $y $txt
$wnd DrawImage $drw
magick delete $drw
magick delete $clr
}

used:

annotate $wnd 20 20 0 "This is my Caption"

Hope this helps ...

Cheers,
Rob.

.



Relevant Pages