Example #1
0
// No GD support, die.
if (!$im) {
    die("No GD support.");
}
// Fill the background with white
$bg_color = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg_color);
// Draw random circles, squares or lines?
$to_draw = my_rand(0, 2);
if ($to_draw == 1) {
    draw_circles($im);
} else {
    if ($to_draw == 2) {
        draw_squares($im);
    } else {
        draw_lines($im);
    }
}
// Draw dots on the image
draw_dots($im);
// Write the image string to the image
draw_string($im, $imagestring);
// Draw a nice border around the image
$border_color = imagecolorallocate($im, 0, 0, 0);
imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $border_color);
// Output the image
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
/**
 * Draws a random number of lines on the image.
}
function generate_image($code, $im)
{
    global $characters;
    global $symbol_width;
    global $height;
    for ($i = 0, $x = 0; $i < strlen($code); $i++, $x += $symbol_width) {
        $char_im = get_char_by_index_from_font($characters[$code[$i]]);
        imagecopymerge($im, $char_im, $x, 0, 0, 0, $symbol_width, $height, 100);
    }
    return $im;
}
global $symbol_width;
global $height;
global $characters;
$symbol_width = 20;
$width = strlen($generation_str) * $symbol_width + 20;
$height = 20;
$code = $generation_str;
$bg_color = array('red' => 255, 'green' => 255, 'blue' => 255, 0 => 255, 1 => 255, 2 => 255);
$text_color = array('red' => 0, 'green' => 0, 'blue' => 0, 0 => 0, 1 => 0, 2 => 0);
$characters = array('1' => 0, '2' => 1, '3' => 2, '4' => 3, '5' => 4, '6' => 5, '7' => 6, '8' => 7, '9' => 8, '0' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, 'Z' => 35);
$im = imagecreatetruecolor($width, $height);
$bgcolor = imagecolorallocate($im, $bg_color['red'], $bg_color['green'], $bg_color['blue']);
imagefilledrectangle($im, 0, 0, imagesx($im), imagesy($im), $bgcolor);
$im = generate_image($code, $im);
$im = wave($text_color, $bg_color, $im, $width, $height);
$im = draw_lines($im, $width - 10, $height + 20);
header("Content-type:image/png");
imagepng($im);
imagedestroy($im);