基于PHP制作验证码

2019-05-02 21:13:56于丽

imagefill — 区域填充
bool imagefill ( resource $image , int $x , int $y , int $color )
imagefill() 在 image图像的坐标 x,y(图像左上角为 0, 0)处用 color颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。

imagerectangle — 画一个矩形
bool imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $col )
imagerectangle() 用 col 颜色在 image 图像中画一个矩形,其左上角坐标为 x1, y1,右下角坐标为 x2, y2。图像的左上角坐标为 0, 0。

imageline — 画一条线段
bool imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )
imageline() 用 color颜色在图像 image 中从坐标 x1,y1 到 x2,y2(图像左上角为 0, 0)画一条线段。

imagestring — 水平地画一行字符串
bool imagestring ( resource $image , int $font , int $x , int $y , string $s , int $col )
imagestring() 用 col颜色将字符串 s 画到 image所代表的图像的 x,y坐标处(这是字符串左上角坐标,整幅图像的左上角为 0,0)。如果 font 是 1,2,3,4 或 5,则使用内置字体。

imagepng — 以 PNG 格式将图像输出到浏览器或文件
imagepng() 将 GD 图像流(image)以 PNG 格式输出到标准输出(通常为浏览器),或者如果用 filename 给出了文件名则将其输出到该文件。

imagedestroy — 销毁一图像

imagedestroy() 释放与 image 关联的内存。

将源代码保存为code.php是个php文件,我们该如何使用他呢?

imagepng已经将这个php文件输出成了png文件

直接调用就可以了

<img src="mycode.php"/>

如果要使用验证码,记得开启session哦

<?php
session_start();
echo $_SESSION['code'];
?>

希望本文所述对大家PHP程序设计有所帮助。

相关文章 大家在看