Light weight captcha image generator for php based web projects. It consists of just one file and three sample fonts. ImageMagic is used for image generation.
sample 1 | sample 2 | sample 3 |
One can adjust generated string length, resulting image size in pixels, text color and background color.
sample 4 | sample 5 | sample 6 |
PHP in general
$captcha = new OutlineCaptcha();
$captcha->setFontPath('/path/to/fonts');
$captchaInfo = $captcha->createCaptchaImage();
$captchaString = $captchaInfo["string"];
$captchaImage = $captchaInfo["image"];
<img src="<?php echo $captchaImage ?>"/>
Laravel
$captcha = $this->app->make('OutlineCaptcha');
$captchaInfo = $captcha->createCaptchaImage();
$captchaString = $captchaInfo["string"];
$captchaImage = $captchaInfo["image"];
<img src="{!! $captchaImage !!}"/>
Overriding default settings
$captchaOptions = [
"width"=>150,
"height"=>100,
"length"=>3,
"fileType"=>"png",
"color"=>'rgb(133, 244, 199)',
"background"=>'rgb(33, 77, 77)'
];
$captcha = new OutlineCaptcha($captchaOptions);
// Laravel
// $captcha = $this->app->make('OutlineCaptcha', [$captchaOptions]);
Copy OutlineCaptcha.php to your application classes directory. Copy outlineFonts folder to your application resources. For the program to know where the fonts are you should either:
- Call setFontPath funtion like $captcha->setFontPath('/path/to/fonts') every time you create OutlineCaptcha class.
or:
- Adjust the fisrt line of OutlineCaptcha class constructor.
Some options can result in totally unreadable captcha image.
- When you decrease image pixel length it is harder to read the resulting captcha and reverse.
- When you increase captcha string length it is harder to read the resulting captcha and reverse.
Try to use simple and distinctive colors.
The Outline Captcha utility is open-sourced software licensed under the MIT license.