Class: SmartImageCaptcha - A Flat Image Plugin for SmartCaptcha
Create a Form Captcha Validation Image (PNG / GIF / JPEG)
If SVG mode is used it will embed the Image into a SVG container to make harder the job of captcha solvers
Language: PHP
Located at: modules/mod-captcha/libs/SmartImageCaptcha.php
Package: modules:development:Captcha
Namespace: \SmartModExtLib\Captcha\
Class Name: SmartImageCaptcha
Version: v.20221220
Depends: extensions: PHP GD Extension w. *optional TTF support ; classes: Smart, SmartFileSysUtils
class Methods
publicfunction__construct (
) {} @
Class Constructor
publicfunctiondraw_image (
) {} -> STRING
@return: {STRING} The Captcha Image
Generate the code and the Image
publicfunctionget_code (
) {} -> STRING
@return: {STRING} The Captcha generated code
Get the generated code
Must be call only after draw_image()
class Properties
public$format = 'svg' ; ->ENUM
Captcha Format
possible values: svg | png | gif | jpg
public$mode = 'dotted' ; ->ENUM
Captcha Mode (hashed is 10x slower than dotted)
possible values: dotted | hashed
public$noise = 100 ; ->INTEGER+
Captcha Noise Level
possible values: 10..1000
public$width = 160 ; ->INTEGER+
Captcha Image Width
possible values: 80..320
public$height = 40 ; ->INTEGER+
Captcha Image Height
possible values: 40..160
public$quality = 90 ; ->INTEGER+
Captcha Image Quality
Applies only for jpeg format
possible values: 20..100
public$pool = '01234567890' ; ->STRING
Captcha Characters Pool (the list of characters from where the Captcha will pick random characters)
possible values (from this list) '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
public$chars = 5 ; ->INTEGER+
Captcha Characters Number (how many characters from the possible characters list to pickup randomly and display)
possible values: 3..7
public$charspace = 8 ; ->INTEGER+
Captcha Display Tunnings - Characters Space
public$charxvar = 7 ; ->INTEGER+
Captcha Display Tunnings - Characters X space start (5..50)
public$charyvar = 8 ; ->INTEGER+
Captcha Display Tunnings - Characters Y space start (5..25)
Captcha Display Tunnings - Font
possible values: 1..5 as INTEGER will use the GD built-in font ; as STRING can be a relative path to a GDF font as 'path/to/font.gdf' or to a TTF font as 'path/to/font.ttf'
public$charttfsize = 20 ; ->INTEGER+
Captcha Display Tunnings - TTF Font Size (apply just for TTF fonts ; the GDF fonts are not scalable)
possible values: 10..70
public$overlines = 0 ; ->INTEGER+
Captcha Display Tunnings - Apply random lines over the image ; If > 0 will apply a number of lines over the image
possible values: 0..9
public$distort = false ; ->BOOLEAN
Captcha Display Tunnings - Apply distort for the image ; If TRUE will distort the image with a random value
public$sketchy = false ; ->BOOLEAN
Captcha Display Tunnings - Apply sketchy filter to the image ; If TRUE will apply a sketchy filter to the image
public$emboss = false ; ->BOOLEAN
Captcha Display Tunnings - Apply emboss filter to the image ; If TRUE will apply a emboss filter to the image
public$scatter = false ; ->BOOLEAN
Captcha Display Tunnings - Apply scatter filter to the image ; If TRUE will apply a scatter filter to the image
public$negate = false ; ->BOOLEAN
Captcha Display Tunnings - Apply negate filter to the image ; If TRUE will negate the image colors
public$contrast = false ; ->BOOLEAN
Captcha Display Tunnings - Apply contrast to the image ; If TRUE will apply a random contrast to the image
public$colorize = false ; ->BOOLEAN
Captcha Display Tunnings - Apply colorize effect to the image ; If TRUE will apply a random colorize effect to the image
public$grayscale = false ; ->BOOLEAN
Captcha Display Tunnings - Apply grayscale effect to the image ; If TRUE will apply a grayscale effect to the image
class Constants
Sample code: PHP
<?php
//-- set the captcha options $captcha = new SmartImageCaptcha(); $captcha->format='png'; $captcha->width = 100; $captcha->height = 50; $captcha->noise = 300; $captcha->chars = 5; $captcha->charfont = 'modules/mod-captcha/fonts/barrio.ttf'; // or a .gdf font if GD have no TTF support $captcha->charttfsize = 24; $captcha->charspace = 18; $captcha->charxvar = 11; $captcha->charyvar = 22; //-- output captcha image header('Content-Type: image/png'); echo $captcha->draw_image(); // raw output the captcha image //-- use captcha generated code to store somewhere echo $captcha->get_code(); //--
// #end php code
documentation generated on: 2023-10-19 23:15:55 +0000
Create a Form Captcha Validation Image (PNG / GIF / JPEG)
If SVG mode is used it will embed the Image into a SVG container to make harder the job of captcha solvers