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等格式上添加文字设置坐标可以放在任意的地方 union all效率低下,该用存储过程、视图、临时表哪种方法来解决? 关于mysql NULL的一个问题 linux 下php5无法载入mysql扩展 懂Linux xampp的帮忙一下 请高手回答 mysql查找a最小的b不能重复的以a排序的前3名怎么写 求SQL语句或方法:字段频率排序 c++与php脚本交互时发生的一些问题 嵌入框架的问题,急!!20分相送!! 关于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等格式上添加文字
设置坐标可以放在任意的地方