<?php
Ob_end_flush();
//注意,在此之前不能向浏览器输出任何信息,要注意是否设置了 auto_prepend_file.
header ("Content-type: image/png");
$im = @imagecreate (200, 100)
or die ("无法创建图像");
$background_color = imagecolorallocate ($im, 0,0, 0);
$text_color = imagecolorallocate ($im, 230, 140, 150);
imagestring ($im, 3, 30, 50, "A Simple Text String", $text_color);
imagepng ($im);
?>
Ob_end_flush();
//注意,在此之前不能向浏览器输出任何信息,要注意是否设置了 auto_prepend_file.
header ("Content-type: image/png");
$im = @imagecreate (200, 100)
or die ("无法创建图像");
$background_color = imagecolorallocate ($im, 0,0, 0);
$text_color = imagecolorallocate ($im, 230, 140, 150);
imagestring ($im, 3, 30, 50, "A Simple Text String", $text_color);
imagepng ($im);
?>
//随机字符串函数
function my_random_password($length)
{
$result = "";
$string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for ($i = 0 ; $i < $length ; $i++)
{
$result .= $string[mt_rand(0 , strlen($string) - 1)];
}
return $result;
}
//判断是否需要加载相应的gd库
if (!extension_loaded('gd'))
{
if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN'))
{
dl('php_gd2.dll');
}
else
{
dl('gd2.so');
}
}
?>
<?
//告诉浏览器发送的是png图片
header ("content-type: image/png");
//图像长宽初始化
$image_x = 100;
$image_y = 40;
//创建图片
$image = imagecreate($image_x , $image_y);
//定义背景色
$background_color = imagecolorallocate($image , 0xFF , 0xFF , 0xFF);
//定义所需要的颜色
$black_color = imagecolorallocate($image , 0x00 , 0x00 , 0x00);
$gray_color = imagecolorallocate($image , 0xcc , 0xcc , 0xcc);
//循环生成雪花点
for ($i = 0 ; $i < 1000 ; $i++)
{
imagesetpixel($image , mt_rand(0 , $image_x) , mt_rand(0 , $image_y) , $gray_color);
}
//把随机字符串输入图片
imagestring($image , 4 , 20 , 12 , my_random_password(8) , $black_color);
//生成矩形边框
imagerectangle($image , 0 , 0 , $image_x - 1 , $image_y - 1 , $black_color);
//生成图片
imagepng($image);
//释放与$image关联的内存
imagedestroy($image);
?>这样可以生成一个验证码!并可以显示!
但是在?> <? 中间加入
<form action=gd.php method=POST>
<table>
请输入验证码:<input type=text name=authinput style="width: 80px"><br/>
<input type=submit name="验证" value="提交验证码">
</table>
</form>
//注意,在此之前不能向浏览器输出任何信息,要注意是否设置了 auto_prepend_file.
header ("Content-type: image/png");另外我做的GD库的应用
我的圣诞图形编辑flash发布
http://www.yuhuatel.com/yang/xmas/
目前支持在图片上写字,画线,贴图,最终生成图片保存等,你可以看看