搭建php运行环境,搜索XAMPP下载安装。
打开xampp文件地址,在站点文件夹htdots下,新建一个php文件。输入简单的内容判断是否能正常运行。
检查php是否支持GD,输入<?php phpinfo():查看输出即可。
实现简单的验证码
在htdots站点下,打开project目录创建php文件;
生成底图:图像绘制imagecreatetruecolor(int $width,int $height) 。
header方法输出图片的类型;
imagecreatetruecolor(int $width,int $height) 。默认返回黑色底图。
imagecolorallocate($image,int red,int green,int blue)为图像分配颜色。
9.imagefill($image,int x,int y,int color)区域填充,在iamge图像的坐标x,y(图像左上角为(0,0)处用color颜色执行区域填充;
<?php
//phpinfo();
//生成验证码底图
$image=@imagecreatetruecolor(120, 20);//返回一个黑色的图片
$text_color = imagecolorallocate($image, 255, 255, 255);
// $bgcolor=imagecolorallocate($image,255,255,255);
// imagefill($image,0,0,$bgcolor);
// header('content-type: image/png');
// imagedestroy($image);
imagefill($image,0,0,$text_color);//区域填充
header ('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
实现简单的验证码
<?php $image = imagecreatetruecolor(100,50); //生成一张100*50大小的图片(底图) header("content-type:image/png"); //定义图片格式为png 注意header一定要在image输出图像之前 $bgcolor = imagecolorallocate($image,200,200,200); //为一幅图分配颜色 imagefill($image,0,0,$bgcolor); //将颜色填充到底图上 imagepng($image); //区域填充 imagedestroy($image); //销毁资源,便于回收
gd使用
实现底图