<?php
session_start();
$arr = array("我","人","有","的","和","主","产");
$im = @imagecreatetruecolor(100,30) or die("Cannot Initialize new GD image stream");
// 背景设为红色
$background = imagecolorallocate($im, 255, 0, 0);
// 设定一些颜色
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 124, 254, 168);
$fontcolor = imagecolorallocate($im, 57, 198, 57);
//画线 bool imageline(resource image,int x1,int y1,int x2,int y2,int color)
for($i=0; $i<5; $i++)
{
imageline($im,rand(0,100),rand(0,30),rand(80,100),rand(11,30),$white);
}
//画点bool imagesetpixel ( resource image, int x, int y, int color )
for($i=0; $i<300; $i++)
{
imagesetpixel($im,rand(0,100),rand(0,30), $black );
}
//添加文字
shuffle($arr);
$str=$arr[0].$arr[1];
$_SESSION["gd"] = $str;
$str = iconv('gb2312','utf-8',$str);
//imagestring($im, 5, 0, 0, $str, $white);
imagettftext($im, 20, 0, 15, 20, $fontcolor, "JDJK.TTF", $str);
imagejpeg($im);
//imagedestroy($im);
//@session_write_close();
?>