Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php

CAPTCHA


Creates a six-alphanumeric-character image for use as a challenge response test

Download Script

last modified: September 26, 2017



USAGE: captcha [-f font] [-p pointsize] [-t textcolor] [-u undercolor] [-b bordercolor] [-m mode] [-a angle] [-r resize] outfile
USAGE: captcha [-h or -help]

-f .... font .............. fontname or path-to-font-file; default=TimesNewRoman
-p .... pointsize ......... pointsize for font; default=40
-t .... textcolor ......... color of text; any IM color specification; default=black
-u .... undercolor ........ background color under text; any IM color specification;
........................... default=white;
-b .... bordercolor ....... color of image border; any IM color specification;
........................... default=black;
-m .... mode .............. mode to orient text: skew, rotate, both; default=skewx
-a .... angle ............. maximum orientation angle of text used with mode;
........................... default=40 (degrees); Values are integers 0<=angle<=60
-r .... resize ............ output image resize in percent; default=100 (percent) which
........................... produces an image 300x80 pixels

PURPOSE: To create a six-alphanumeric-character image for use as a challenge response test.

DESCRIPTION: CAPTCHA creates a six-alphanumeric-character image for use as a challenge response test. It builds a default image of size 300x80 pixels containing 6 alphanumeric characters that are randomly positioned and oriented and overlaid with random curved and straight lines segments.

ARGUMENTS:

-f font ... FONT is the desired font or path-to-font-file for the text. The default is TimesNewRoman.

-p pointsize ... POINTSIZE is the desired pointsize for the font. The default is 40.

-t textcolor ... TEXTCOLOR is the color to apply to the text. Any valid IM text color may be used. The default is black. See http://imagemagick.org/script/color.php

-u undercolor ... UNDERCOLOR is the background color to apply directly under the text. Any valid IM text color may be used. The default is white. See http://imagemagick.org/script/color.php

-b bordercolor ... BORDERCOLOR is the color to apply to the image border. Any valid IM text color may be used. The default is black. See http://imagemagick.org/script/color.php

-m mode ... MODE is the mode for randomly orienting the text. The choices are: skew, rotate or both.

-a angle ... ANGLE is the maximum angle to use to randomly orient the text. The default=40 (degrees). Values are integers, 0<=angle<=60

-r resize ... RESIZE is the percentage of the default output image size of 300x80 to use to generate the output image. The default is 100 (percent). All images are created at a size of 300x80, including a 5 pixel border. If resize is specified, the output image will be resized accordingly by a post-processing step using the IM -resize function.

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES


Examples

 

Arguments:
(default)

 

Arguments:
(default)

 

Arguments:
-f TimesNewRoman -p 40 -t blue -u white -b red -m skew -a 40 -r 100

 

Arguments:
-f TimesNewRoman -p 40 -t blue -u white -b red -m skew -a 40 -r 100


What the script does is as follows:

  • Creates a base image with border using the user provided colors
  • Randomly selects 6 alphanumeric text characters, positions and orientations
  • Inserts the 6 characters at the randomly selected positions and orientations

This is equivalent to the following IM commands for the case of the default settings:

  • Calculations to randomize characters, positions and orientations
  • convert -size 290x70 xc:white -bordercolor black -border 5 \
    -fill black -stroke black -strokewidth 1 -font TimesNewRoman -pointsize 40 \
    -draw "translate ${xx1},${yy1} skewX $ss1 gravity center text 0,0 '$cc1'" \
    -draw "translate ${xx2},${yy2} skewX $ss2 gravity center text 0,0 '$cc2'" \
    -draw "translate ${xx3},${yy3} skewX $ss3 gravity center text 0,0 '$cc3'" \
    -draw "translate ${xx4},${yy4} skewX $ss4 gravity center text 0,0 '$cc4'" \
    -draw "translate ${xx5},${yy5} skewX $ss5 gravity center text 0,0 '$cc5'" \
    -draw "translate ${xx6},${yy6} skewX $ss6 gravity center text 0,0 '$cc6'" \
    -fill none -strokewidth 2 \
    -draw "bezier ${bx1},${by1} ${bx2},${by2} ${bx3},${by3} ${bx4},${by4}" \
    -draw "polyline ${bx4},${by4} ${bx5},${by5} ${bx6},${by6}" \
    $outfile