kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

PHPGD 验证码

https://m.php.cn/faq/544577.html

https://www.php.cn/faq/383496.html

1
2
3
4
5
6
7
8
1、产生一张png的图片
2、为图片设置背景色
3、设置字体颜色和样式
4、产生4位数的随机的验证码
5、把产生的每个字符调整旋转角度和位置画到png图片上
6、加入噪点和干扰线防止注册机器分析原图片来恶意注册
7、输出图片
8、释放图片所占内存
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function phpgd()
{
	$code = "";
	$charset = "ABCDEFGHJKMNPQRSTUWXY3456789"; // 去掉 I O Z 0 1 2
	$charset_length = strlen($charset);

	for ($i = 0; $i < 4; $i++) {
		$rand_index = rand(0, $charset_length - 1);
		$rand_char = substr($charset, $rand_index, 1);
		$code .= $rand_char;
	}

	$_SESSION["captcha"] = $code;

	// 展示验证码图片
	$image_width = 120;
	$image_height = 40;
	$image = imagecreatetruecolor($image_width, $image_height);
	$bg_color = imagecolorallocate($image, 255, 255, 255);
	imagefill($image, 0, 0, $bg_color);

	$font_size = 20;
	$font_color = imagecolorallocate($image, 0, 0, 0);

	$x = 10;
	$y = ($image_height - $font_size) / 2 + $font_size;
	for ($i = 0; $i < 4; $i++) {
		$char = substr($code, $i, 1);
		imagettftext($image, $font_size, rand(-10, 10), $x, $y, $font_color, "/usr/share/fonts/open-sans/OpenSans-Bold.ttf", $char);
		$x += $font_size + rand(5, 10);
	}

	$x = $image_width;
	$y = $image_height;
	// 干扰线
	for ($i = 0; $i < 8; $i ++) {
		$lineColor = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
		imageline($image, rand(0, $x), 0, rand(0, $x), $y, $lineColor);
	}
	// 干扰点
	for ($i = 0; $i < 200; $i ++) {
		$fontColor = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
		imagesetpixel($image, rand(0, $x), rand(0, $y), $fontColor);
	}

	header('Content-Type: image/png');
	imagepng($image);
	imagedestroy($image);
}

https://blog.csdn.net/bzjoko/article/details/128786504

字体

1
/usr/share/fonts/

https://blog.csdn.net/allway2/article/details/126685336

imagettftext() 函数 是 PHP 中的一个内置函数,用于使用 TrueType 字体将文本写入图像。

句法:

参数:此函数接受上述八个参数,如下所述:

1
2
3
4
5
6
7
8
$image:它指定要处理的图像。
$size:它指定要使用的字体大小,以磅为单位。
$angle:它以度为单位指定角度。
$x:指定 x 坐标。
$y:它指定 y 坐标。
$color:它指定文本所需颜色的索引。
$fontfile:它指定要使用的字体。
$text:它指定要写入的文本。

返回值:此函数在成功时返回一个数组。