Customizing Securimage

Note: Securimage is a legacy self-hosted PHP CAPTCHA. Modern applications should use hCaptcha or Cloudflare Turnstile instead.

You can change colors, fonts, image dimensions, distortion, line count, and character set. Edit securimage_show.php (recommended) or the __construct() function in securimage.php.

All examples below use securimage_show.php.

Changing Colors

Colors use the Securimage_Color class. Pass RGB values or an HTML hex string:

<?php
// RGB values (0–255)
$color = new Securimage_Color(0, 0, 255); // blue

// Hex string
$color = new Securimage_Color('#3388FF');

// Shorthand hex
$color = new Securimage_Color('#38F');

Set background, text, and line colors:

<?php
// In securimage_show.php, before $img->show()

$img->image_bg_color = new Securimage_Color('#ffffff'); // white background
$img->text_color     = new Securimage_Color('#525252'); // dark grey text
$img->line_color     = new Securimage_Color('#525252'); // matching line color

Using Background Images

Securimage can use one static background image or pick randomly from a directory. Backgrounds should match the image size (230×80px by default) but get resized if they don't.

For a single background, pass the full path to show():

<?php
// Last line of securimage_show.php — full path required
$img->show('/home/user/public/securimage/backgrounds/image.png');

// Windows path
$img->show('C:\\inetpub\\wwwroot\\securimage\\backgrounds\\image.png');

For random backgrounds, set a directory:

<?php
// Set background directory (dirname resolves the path automatically)
$img->background_directory = dirname(__FILE__) . '/backgrounds/';

Drop PNG, JPG, or GIF images into the backgrounds/ folder. Securimage ships with a few samples; replace or add to them.

Adjusting Difficulty

Two properties control difficulty: distortion and line overlays.

Distortion uses perturbation (0 = none, 1 = maximum). Default is 0.75. Above 1, humans struggle too.

Lines use num_lines. More lines means harder reading — for bots and users alike.

<?php
// Default distortion
$img->perturbation = 0.75;

// High distortion — use carefully
$img->perturbation = 1.0;

// No distortion — easiest to read
$img->perturbation = 0;

// Many lines over the image
$img->num_lines = 10;

// No lines
$img->num_lines = 0;

Custom Fonts

Any TTF font works. Switching from the default makes your CAPTCHA harder for bots that were trained against it. Drop TTF files into the Securimage folder (next to AHGBold.ttf) — no spaces or special characters in filenames.

<?php
// Use a custom TTF font from the securimage directory
$img->ttf_file = $img->basepath . '/myfont.ttf';

// Or with an absolute path if the font is elsewhere
$img->ttf_file = '/home/user/public/fonts/myfont.ttf';

Adding a Signature

Signatures render small text in the bottom-right corner — typically your domain name.

<?php
$img->image_signature = 'yoursite.com';
$img->signature_color = new Securimage_Color('#000000'); // black

Adjusting Image Size

Set image_width and image_height. Keep width at least 2.7× the height or characters won't have room to render.

<?php
// Set width, calculate optimal height
$img->image_width  = 260;
$img->image_height = (int)($img->image_width * 0.35); // = 91px

// Or set height and calculate width
$img->image_height = 50;
$img->image_width  = (int)($img->image_height * 2.875); // = 143px

Changing the Character Set

By default, Securimage uses [a-zA-Z0-9] minus ambiguous characters (I, J, O, Q, i, j, o, q, 0, 1). Override with any string of characters.

<?php
// Capital letters only
$img->charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

// Numbers only
$img->charset = '0123456789';

// Lowercase and numbers, excluding ambiguous characters
$img->charset = 'abcdefghklmnprstuvwyz23456789';

Repeating a character increases its probability of appearing.

Randomizing Properties

Fixed code length or line count gives bots a stable target. Randomize between loads so they can't lock in.

<?php
// Variable code length (4 to 6 characters)
$img->code_length = rand(4, 6);

// Random number of lines
$img->num_lines = rand(3, 10);

Related