GD库生成图片加字怎么实现 http://www.mtmer.com/bbs/hack.php?H_name=idcards 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?php$w = 80; // 图片宽度$h = 26; // 图片高度$str = Array();$vcode = "";$scrstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";for ( $i = 0; $i < 4; $i++ ) { // 随机生成一个验证码 $str[$i] = $scrstr[ rand (0, 35 ) ]; // 用rand()函数产生一个0~35的随机整数 $vcode .= $str[$i]; }session_start(); // 启动一个会话$_SESSION["vcode"] = $vcode; // 将验证码保存在会话变量中$im = imagecreatetruecolor ( $w, $h ); // 创建一个真彩色图像$white = imagecolorallocate ( $im, 255, 255, 255 ); // 分配颜色$black = imagecolorallocate ($im, 0, 0, 0);imagefilledrectangle ( $im, 0, 0, $w, $h, $white ); // 用白色画矩形并填充imagerectangle ( $im, 0, 0, $w - 1, $h - 1, $black ); // 用黑色画图片边框// 以下循环语句用于生成图像的雪花背景for ( $i = 1; $i < 200; $i++ ) { $x = mt_rand ( 1, $w - 9 ); // 用mt_rand()函数生成随机数 $y = mt_rand (1, $h - 9 ); $color = imagecolorallocate ( $im, mt_rand ( 200, 255 ), mt_rand ( 200, 255 ), mt_rand ( 200, 255 ) ); // 随机生成一种颜色 imagechar ( $im, 1, $x, $y, "*", $color ); // 在图像中写入一个星号}// 以下循环语句用于将验证码写入图像中for ( $i = 0; $i < count($str); $i++ ) { $x = 13 + $i * ( $w -15 ) / 4; $y = mt_rand ( 3, $h / 3 ); $color = imagecolorallocate ( $im, mt_rand ( 0, 225 ), mt_rand ( 0, 150 ), mt_rand ( 0, 225 ) ); imagechar ($im, 5, $x, $y, $str[$i], $color );}header("Content-type:image/jpeg");imagejpeg ( $im );//imagedestroy ( $im );?>用的时候 将图片的src设成这个文件就好了! 你的这个是验证码我说的是名片生成系统就是在GIF,JPG,BMP,SWF,PNG等格式上添加文字设置坐标可以放在任意的地方 php 读取 "特殊" 文本文件 appserv在联网的时候为什么无法使用? 自己想做一些由PC控制的机械 MYSQL有删除特定表的语法么? 菜鸟一个问题。。。。 这条insert 语句为什么不好用? linux下关于apache+php+mysql PHP做网站 mail函数中如何发送html邮件? ckeditor 4.5.8 的上传处理页 upload.php里应该怎么写,才能上传到目录下? Google分页如何连接数据库 正则问题
$w = 80; // 图片宽度
$h = 26; // 图片高度
$str = Array();
$vcode = "";
$scrstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for ( $i = 0; $i < 4; $i++ ) { // 随机生成一个验证码
$str[$i] = $scrstr[ rand (0, 35 ) ]; // 用rand()函数产生一个0~35的随机整数
$vcode .= $str[$i];
}
session_start(); // 启动一个会话
$_SESSION["vcode"] = $vcode; // 将验证码保存在会话变量中
$im = imagecreatetruecolor ( $w, $h ); // 创建一个真彩色图像
$white = imagecolorallocate ( $im, 255, 255, 255 ); // 分配颜色
$black = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ( $im, 0, 0, $w, $h, $white ); // 用白色画矩形并填充
imagerectangle ( $im, 0, 0, $w - 1, $h - 1, $black ); // 用黑色画图片边框
// 以下循环语句用于生成图像的雪花背景
for ( $i = 1; $i < 200; $i++ ) {
$x = mt_rand ( 1, $w - 9 ); // 用mt_rand()函数生成随机数
$y = mt_rand (1, $h - 9 );
$color = imagecolorallocate ( $im, mt_rand ( 200, 255 ),
mt_rand ( 200, 255 ), mt_rand ( 200, 255 ) ); // 随机生成一种颜色
imagechar ( $im, 1, $x, $y, "*", $color ); // 在图像中写入一个星号
}
// 以下循环语句用于将验证码写入图像中
for ( $i = 0; $i < count($str); $i++ ) {
$x = 13 + $i * ( $w -15 ) / 4;
$y = mt_rand ( 3, $h / 3 );
$color = imagecolorallocate ( $im, mt_rand ( 0, 225 ),
mt_rand ( 0, 150 ), mt_rand ( 0, 225 ) );
imagechar ($im, 5, $x, $y, $str[$i], $color );
}
header("Content-type:image/jpeg");
imagejpeg ( $im );
//imagedestroy ( $im );
?>用的时候 将图片的src设成这个文件就好了!
你的这个是验证码
我说的是名片生成系统
就是在GIF,JPG,BMP,SWF,PNG等格式上添加文字
设置坐标可以放在任意的地方