Example #1
0
<?php

/**
 * @author Gutsulyak Vadim <*****@*****.**>
 */
session_start();
header("Content-type: image/png");
$image = imagecreate(100, 30);
imagecolorallocate($image, 255, 255, 255);
$captchaString = randString(6);
printCrazy($image, $captchaString, 5, 20);
$_SESSION['captcha'] = $captchaString;
for ($i = 0; $i < 3; $i++) {
    $color = imagecolorallocate($image, rand(100, 200), rand(100, 200), rand(100, 200));
    imageline($image, 0, rand(0, 30), 100, rand(0, 30), $color);
}
imagepng($image);
function randString($length)
{
    $result = "";
    for ($i = 0; $i < $length; $i++) {
        $result .= chr(rand(65, 90));
    }
    return $result;
}
function printCrazy($image, $text, $x, $y)
{
    $chars = str_split($text);
    $font = "albionic.ttf";
    foreach ($chars as $char) {
        $size = rand(12, 15);
Example #2
0
<?php

/**
 * @author Gutsulyak Vadim <*****@*****.**>
 */
// указываем тип возвращаемого контента
header('Content-type: image/png');
// создаём картинку 300х75
$image = imagecreate(300, 300);
// заливаем картинку цветом
$bgColor = imagecolorallocate($image, 0, 0, 0);
$textColor = imagecolorallocate($image, 250, 0, 0);
imagestring($image, 5, 100, 30, "Hello World", $textColor);
imagettftext($image, 20, 0, 50, 130, $textColor, "albionic.ttf", "Wello World");
printCrazy($image, "crazy text", 10, 200);
// выводим
imagepng($image);
function printCrazy($image, $text, $x, $y)
{
    $chars = str_split($text);
    $font = "albionic.ttf";
    foreach ($chars as $char) {
        $size = rand(20, 25);
        $color = imagecolorallocate($image, rand(100, 200), rand(100, 200), rand(100, 200));
        $angle = rand(-20, 20);
        imagettftext($image, $size, $angle, $x, $y, $color, $font, $char);
        $x += 30;
    }
}