去掉 image.php 中 <?php ... ?> 之外的全部内容
解决方案 »
- 跪求PHP学习资料
- 出现Warning: Call-time pass-by-reference has been deprecated in 这种警告怎会解决?(急)
- 请教
- 一个想学PHP语言的求助者!!求业内好心人士指学迷津!!
- PHP 项目在IE 和 火狐中不兼容的问题要怎么解决....有图有真相
- 我想求一个可以批量上传文件的PHP实例,可否给点启发
- header("WWW-Authenticate:Basic realm=\"网张使用者\"") 怎么会有错?
- 这是PHP上传文件代码,怎样更换上传目录
- curl的一些小问题
- php连接不了MySQL
- php插入数据乱码,全部设置都为UTF-8
- 请问一个问题,数据库文章以不同排版的方式显示
image.php只保留php的部分就好了。
<?php
/*
* 生成图片验证码
* and open the template in the editor.
*/
session_start();
for($i=0;$i<4;$i++){
$rand.=dechex(rand(1,15)); //生成4位数包含十六进制的随机数
}
$_SESSION[check_gd]=$rand;
$img=imagecreatetruecolor(100,30); //创建图片
$bg=imagecolorallocate($img,0,0,0); //第一次生成的是背景颜色
$fc=imagecolorallocate($img,255,255,255); //生成的字体颜色
//给图片画线
for($i=0;$i<3;$i++){
$te=imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imageline($img,rand(0,15),0,100,30,$te);
}
//给图片画点
for($i=0;$i<200;$i++){
$te=imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($img,rand()%100,rand()%30,$te);
}
//首先要将文字转换成utf-8格式
//$str=iconv("gb2312","utf-8","呵呵呵");
//加入中文的验证
//smkai.ttf是一个字体文件,为了在别人的电脑中也能起到字体作用,把文件放到项目的根目录,可以下载,还有本机C:\WINDOWS\Fonts中有
imagettftext($img,11,10,20,20,$fc,"simkai.ttf","你好你好");
//把字符串写在图片中
//imagestring($img,rand(1,6),rand(3,70),rand(3,16),$rand,$fc);
//输出图片
header("Content-type:image/jpeg");
imagejpeg($img);
?>
另外:imagettftext($img,11,10,20,20,$fc,"simkai.ttf","你好你好");
simkai.ttf的路徑要對。否則會有warning導致圖片不能輸出。