/usr/share/doc/php5-imagick/examples/captcha.php is in php5-imagick 3.1.2-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <?php
/*
A very primitive captcha implementation
*/
/* Create Imagick object */
$Imagick = new Imagick();
/* Create the ImagickPixel object (used to set the background color on image) */
$bg = new ImagickPixel();
/* Set the pixel color to white */
$bg->setColor( 'white' );
/* Create a drawing object and set the font size */
$ImagickDraw = new ImagickDraw();
/* Set font and font size. You can also specify /path/to/font.ttf */
$ImagickDraw->setFont( '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf' );
$ImagickDraw->setFontSize( 20 );
/* Create the text */
$alphanum = 'ABXZRMHTL23456789';
$string = substr( str_shuffle( $alphanum ), 2, 6 );
/* Create new empty image */
$Imagick->newImage( 85, 30, $bg );
/* Write the text on the image */
$Imagick->annotateImage( $ImagickDraw, 4, 20, 0, $string );
/* Add some swirl */
$Imagick->swirlImage( 20 );
/* Create a few random lines */
$ImagickDraw->line( rand( 0, 70 ), rand( 0, 30 ), rand( 0, 70 ), rand( 0, 30 ) );
$ImagickDraw->line( rand( 0, 70 ), rand( 0, 30 ), rand( 0, 70 ), rand( 0, 30 ) );
$ImagickDraw->line( rand( 0, 70 ), rand( 0, 30 ), rand( 0, 70 ), rand( 0, 30 ) );
$ImagickDraw->line( rand( 0, 70 ), rand( 0, 30 ), rand( 0, 70 ), rand( 0, 30 ) );
$ImagickDraw->line( rand( 0, 70 ), rand( 0, 30 ), rand( 0, 70 ), rand( 0, 30 ) );
/* Draw the ImagickDraw object contents to the image. */
$Imagick->drawImage( $ImagickDraw );
/* Give the image a format */
$Imagick->setImageFormat( 'png' );
/* Send headers and output the image */
header( "Content-Type: image/{$Imagick->getImageFormat()}" );
echo $Imagick->getImageBlob( );
?>
|