去掉 image.php 中 <?php ... ?> 之外的全部内容
解决方案 »
- php的基础部分学完了,下面该杂学呢?
- PHP5.3.x 不再支持ISAPI,要用fastCGI方式才能在IIS6下运行PHP5.3????
- vista 下修改apache 配置文件的错误
- Php堕落群 第十二B轮散分宣传
- PHP 如何做二级域名
- 如何用php截取 【标签:标题】 【/标签】 之间的内容
- 中国强人的php,适合学生在网吧用的Apache PHP MySQL phpMyAdmin绿色安装程序只有5m大小,送给到处找php免费空间的测试的同道们
- 关于建立临时表以提高访问速度的疑问
- 急啊!急!我怎么才能上传Mysql数据库?
- 请问php的session是怎么用啊?
- 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導致圖片不能輸出。