-
Notifications
You must be signed in to change notification settings - Fork 0
/
gd_draw.php
121 lines (99 loc) · 3 KB
/
gd_draw.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
define('ACC',true);
require('./system/init.php');
/*
GD 画图
*/
/*
1创建画布,
可以用imageceatetruecolor创建空白画布,
也可以打开一个画布
*/
/*
扭曲验证码
正玄曲线函数,弧度函数
*/
$file = './jym1u4.jpg';
//$im = imagecreatefromjpeg($file);
$im = imagecreatetruecolor(650,500);
//配颜色
$purple = imagecolorallocate($im,0,255,255);
$grey = imagecolorallocate($im,150,150,150);
$render = imagecolorallocate($im,mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
$linecolor1 = imagecolorallocate($im,mt_rand(150,250),mt_rand(150,250),mt_rand(150,250));
$linecolor2 = imagecolorallocate($im,mt_rand(150,250),mt_rand(150,250),mt_rand(150,250));
$linecolor3 = imagecolorallocate($im,mt_rand(150,250),mt_rand(150,250),mt_rand(150,250));
//填充背景
imagefill($im,0,0,$grey);
//画图
$sample = 'qwertyupasdfghjkzxcvbnm23456789';
$csample = array('中','呵','二','想','分','收','人','做');//中文样本
shuffle($csample);
$code = implode('',array_slice($csample,0,4));
/*
$str = substr(str_shuffle($sample),rand(0,strlen($sample)-4),4);
imageline($im, 0,mt_rand(0,25),50,mt_rand(0,25),$linecolor1);
imageline($im, 0,mt_rand(0,25),50,mt_rand(0,25),$linecolor2);
imageline($im, 0,mt_rand(0,25),50,mt_rand(0,25),$linecolor3);
*/
//imagestring($im,5,8,5,$str,$render);
//输出中文
//imagettftext($im,12,0,1,15,$purple,'./simkai.ttf',$code);
//保存图片或者直接输出
/*
//画矩形&椭圆
imagerectangle($im,200,150,600,450,$render);
imageellipse($im,400,300,400,300,$linecolor3);
imageellipse($im,400,300,300,300,$linecolor2);
//填充效果
imagefilledellipse($im,400,300,200,300,$linecolor1);
*/
//画圆弧并填充
/*IMG_ARC_CHORD 1
IMG_ARC_PIE 0
IMG_ARC_NOFILL 2
IMG_ARC_EDGED 4
*/
//imagearc($im,400,300,300,300,270,0,$purple);
//imagearc($im,400,300,310,310,270,0,$render);
imagefilledarc($im,400,300,310,310,270,0,$render,0+2+4);
imagefill($im,200,200,$linecolor1);
//header('content-type: image/png');
//imagepng($im);
imagedestroy($im);
/*
//图片复制
$sw = 131;
$sh = 40;
$big = imagecreatetruecolor($sw*2+10,$sh);
imagefill($big,0,0,$grey);
$small = imagecreatefrompng("./data/uploads/201409/15/fgozj5.png");
//print_r($small);
imagecopy($big,$small,0,0,0,0,$sw,$sh);
imagecopy($big,$small,$sw+10,0,0,0,$sw,$sh);
header('content-type: image/png');
imagepng($big);
imagedestroy($big);
*/
/*
//创建缩略图
$ow = 131;
$oh = 40;
$nw = (int)$ow/2;
$nh = (int)$oh/2;
$dst = imagecreatetruecolor($ow, $oh);
$src = imagecreatefrompng("./data/uploads/201409/15/fgozj5.png");
imagecopyresampled($dst, $src, 0,0,0,0,$nw,$nh,$ow,$oh);
header('content-type: image/png');
imagepng($dst);
imagedestroy($dst);
*/
//透明复制图
$dst = imagecreatefrompng("./data/uploads/201409/15/test.png");
$src = imagecreatefrompng("./data/uploads/201409/15/fgozj5.png");
imagealphablending($src, true);
imagecopymerge($dst,$src,300,200,0,0,131,40,50);
//header('content-type: image/png');
//imagepng($dst);
print_r(getimagesize("./data/uploads/201409/15/test.png"));
imagedestroy($dst);