$im = ImageCreate(200,200);$red = ImageColorAllocate($im,0xFF,0x00,0x00);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
$white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
$ys1 = ImageColorAllocate($im,0xE9,0xB1,0x50);
$ys2 = ImageColorAllocate($im,0x98,0x25,0xCB);
$ys3 = ImageColorAllocate($im,0x40,0x88,0x47);ImageFilledRectangle($im,50,50,150,150,$black);
//点
for($i=0;$i<300;$i++){
ImageSetPixel($im,rand(1,200),rand(1,200),$white);
}
//虚线
for($i=0;$i<10;$i++){
ImageDashedLine($im,rand(1,200),rand(1,200),rand(1,200),rand(1,200),$ys1);
}
//线
for($i=0;$i<10;$i++){
ImageLine($im,rand(1,200),rand(1,200),rand(1,200),rand(1,200),$ys1);
}
//矩形框
for($i=0;$i<3;$i++){
ImageRectangle($im,rand(1,200),rand(1,200),rand(1,200),rand(1,200),$ys1);
}
//矩形面
for($i=0;$i<2;$i++){
ImageFilledRectangle($im,rand(1,200),rand(1,200),rand(1,200),rand(1,200),$ys1);
}
//多边形
$point = array(rand(1,200),rand(1,200),rand(1,200),rand(1,200),rand(1,200),rand(1,200));
ImagePolygon($im,$point,count($point)/2,$ys2);
ImageFilledPolygon($im,$point,count($point)/2,$ys2);
//弧线
ImageArc($im,rand(20,180),rand(20,180),rand(50,150),rand(50,150),rand(0,360),rand(0,360),$ys3);
//打字
ImageString($im,4,20,30,"add word",$ys3);
ImageTTFText($im,30,0,rand(0,50),rand(30,200),$ys3,'msyhbd.ttf',"添加文字");header('Content-Type:image/png');
ImagePNG($im);
?>
/*检查gd库*/
if(!function_exists('imagetypes')) die("ERROR: GD LIB IS NOT LOADED!");
/*设置http头*/
header("Content-type: image/png");
/*设置根目录头*/
define('ROOT_PATH', dirname(__FILE__) . "/");
/*图片宽度和高度*/
$width = 500;
$height = 500;
/*背景图片*/
$bgfile = ROOT_PATH . "test.png";
/*字体文件*/
$font = ROOT_PATH . "MSYH.TTF";
$str = <<
第二行文字
...
还有文字
EOT;/*创建图片*/
$im = @imagecreatetruecolor($width, $height);
/*加载背景图片*/
$bg = @imagecreatefrompng($bgfile);
/*背景颜色. 顺序是 红 绿 蓝*/
$bgcolor = imagecolorallocate($im, 255, 255, 255);
/*应用背景颜色*/
imagefill($im, 0, 0, $bgcolor);
list($bg_width, $bg_height) = getimagesize($bgfile);
/*应用背景图片*/
for ($bg_x = 0; $bg_x < $width; $bg_x += 200) {for ($bg_y = 0; $bg_y < $height; $bg_y += 300) {
imagecopymerge($im, $bg, $bg_x + 10, $bg_y + 10, 0, 0, $bg_width, $bg_height, 40);
}}
/*文字颜色*/
$color = imagecolorallocate($im, 0, 0, 255);
/*文字大小, 单位为像素*/
$fontsize = 20;
/*添加文字*/
//imagettfbbox(
imagettftext($im, $fontsize, 0, 10, $fontsize + 10, $color, $font, $str);
/*输出图片*/
imagepng($im);
imagedestroy($im);
?>
可以,和php验证码类似