$幅=145;
$高さ = 45;
$authcode = vcaptcha_read_code('words.txt') ;
$bg = 'bg/captcha_bg3.jpg';
$img_type = 'png';
/* 検証コードの長さ */
$letters = strlen($authcode);
$img_bg = (function_exists('imagecreatefromjpeg') && ((imagetypes() & IMG_JPG) > 0))
imagecreatefromjpeg($bg) : imagecreatefromgif($bg);
$bg_width = 画像x($img_bg);
$bg_height = 画像sy($img_bg);
$img_org = ((function_exists('imagecreatetruecolor')) && PHP_VERSION >= '4.3')
imagecreatetruecolor($width, $height) : imagecreate($width, $height);
/* 背景画像を元の画像にコピーし、サイズを変更します */
if (function_exists('imagecopyresampled') && PHP_VERSION >= '4.3') // GD 2.x
{
Imagecopyresampled($img_org, $img_bg, 0, 0, 0, 0, $width, $height, $bg_width, $bg_height);
}
else // GD 1.x
{
Imagecopyresize($img_org, $img_bg, 0, 0, 0, 0, $width, $height, $bg_width, $bg_height);
}
画像破壊($img_bg);
$clr = imagecolorallocate($img_org, 255, 255, 255);
/* 境界線を描画します */
imagerectangle($img_org, 0, 0, $width - 1, $height - 1, $clr);
/* 確認コードの高さと幅を取得します */
$x = ($width - (imagefontwidth(5) * $letters)) / 2;
$y = ($height - imagefontheight(5)) / 2;
画像文字列($img_org, 5, $x, $y, $authcode, $clr);
header('有効期限: 1970 年 1 月 1 日木曜日 00:00:00 GMT');
// HTTP/1.1
header('キャッシュ制御: プライベート、ストアなし、キャッシュなし、再検証する必要があります');
header('キャッシュ制御: post-check=0, pre-check=0, max-age=0', false);
// HTTP/1.0
header('プラグマ: キャッシュなし');
if ($img_type == 'jpeg' && function_exists('imagecreatefromjpeg'))
{
header('コンテンツタイプ: 画像/jpeg');
イメージインターレース($img_org, 1);
Imagejpeg($img_org, false, 95);
}
それ以外
{
header('コンテンツタイプ: image/png');
画像png($img_org);
}
画像破壊($img_org);
関数 vcaptcha_read_code($wordlist_file)
{
$fp = @fopen($wordlist_file, 'rb');
(!$fp) が false を返す場合
$fsize = ファイルサイズ($wordlist_file);
If ($fsize ;
If ($fsize
$max = $fsize; // まだかなり小さいですが、シークの範囲が変わります ;
} その他 {
$max = 128;
}
fseek($fp, rand(0, $fsize - $max), SEEK_SET);
$data = fread($fp, 128); // ファイルからランダムな 128 バイトを読み取ります
fclose($fp)
$data = preg_replace("/r?n/", "n", $data);
$start = strpos($data, "n", rand(0, 100)) + 1; // ランダムな開始位置 ;$end = strpos($data, "n", $start); $end = strpos($data, "n", $start); // 単語の終わりを検索します
Return strto lower(substr($data, $start, $end - $start)) // 128 バイトの部分文字列を返します
}
|