$code = array(rand(0, 9), rand(0, 9), rand(0, 9), rand(0, 9), rand(0, 9));
$path = '/tmp/defimgs/'.implode('', $code).'.jpg';
if ($caching && file_exists($path)) {
header("Content-type: image/jpg");
echo file_get_contents($path);
} else {
//## Создаём картинку
$img = imagecreate(200, 50);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
$fc = imagecolorallocate($img, 85, 135, 195);
//## Цвета для шумов
$nc['0'] = imagecolorallocate($img, 000, 000, 255);
$nc['1'] = imagecolorallocate($img, 000, 255, 000);
$nc['2'] = imagecolorallocate($img, 000, 255, 255);
$nc['3'] = imagecolorallocate($img, 255, 000, 000);
$nc['4'] = imagecolorallocate($img, 255, 000, 255);
$nc['5'] = imagecolorallocate($img, 255, 255, 000);
for ($i = 0; $i < 5; $i++)
{
for ($j = 1; $j < 50; $j++)
imagesetpixel($img, rand(1, 200), rand(1, 50), $nc[$i]);
imagettftext($img, 25, rand(-15, 15), $i*35+25, 40, $fc , '/res/fonts/font.ttf', $code[$i]);
}
header("Content-type: image/jpg");
imagejpeg($img);
if ($caching)
imagejpeg($img, $path);
imagedestroy($img);
}
|