Skip to content

Commit 09f0aae

Browse files
Bigskgitee-org
authored andcommitted
update api.php.
1 parent e23c299 commit 09f0aae

File tree

1 file changed

+167
-34
lines changed

1 file changed

+167
-34
lines changed

api.php

Lines changed: 167 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
//Copyright GHINK Network Studio.
33
//LGPLv3.0
44
//---------------------------------------------------------------------//
5-
$stream_opts = [
5+
error_reporting(0);//抑制报错
6+
$stream_opts = [//防止https证书错误
67
"ssl" => [
78
"verify_peer"=>false,
89
"verify_peer_name"=>false,
910
]
10-
]; //读取API JSON并转为数组
11-
$teamjson=file_get_contents("https://api.ghink.net/fah/json/team/?teamid=".$_GET['teamid'],false, stream_context_create($stream_opts));
12-
$donorjson=file_get_contents("https://api.ghink.net/fah/json/donor/?donor=".$_GET['donor'],false, stream_context_create($stream_opts));
11+
];
12+
//读取API JSON并转为数组
13+
$teamjson=file_get_contents("http://api.ghink.net/fah/json/?team=".$_GET['team'],false, stream_context_create($stream_opts));
14+
$donorjson=file_get_contents("http://api.ghink.net/fah/json/?donor=".$_GET['donor'],false, stream_context_create($stream_opts));
1315
$team=json_decode($teamjson, true);
1416
$donor=json_decode($donorjson, true);
1517
//---------------------------------------------------------------------//
@@ -64,33 +66,164 @@
6466
}
6567
}
6668
//---------------------------------------------------------------------//
67-
$canvas = imagecreatetruecolor(465, 92);//载入画布
68-
$background = imagecolorallocatealpha($canvas, 0, 0, 0, 127);//设置背景色
69-
imagefill($canvas, 0, 0, $background);//填充透明色
70-
imagecolortransparent($canvas, $background);//设置背景色
71-
$text_fonts = 'fnt.ttf';//设置字体
72-
$color = imagecolorallocate($canvas, 255, 255, 255);//设置文字颜色
73-
$text_size = 7;//设置文字大小
74-
$logo_url = 'img.png';//设置源图片目录
75-
$logo = @file_get_contents($logo_url);//读取源文件
76-
$logo_img = imagecreatefromstring($logo);//解析为图片
77-
imagecopyresampled($canvas, $logo_img, 0, 0, 0, 0, 465, 92, imagesx($logo_img), imagesy($logo_img));//覆盖图层
78-
//---------------------------------------------------------------------//
79-
//团队部分
80-
imagettftext($canvas, $text_size, 0, 90, 13, $color, $text_fonts, $teamname);//团队名
81-
imagettftext($canvas, $text_size, 0, 100, 30, $color, $text_fonts, $teamid);//团队编号
82-
imagettftext($canvas, $text_size, 0, 100, 48, $color, $text_fonts, $teamrank);//团队排名
83-
imagettftext($canvas, $text_size, 0, 110, 65, $color, $text_fonts, $teamwus);//已完成的任务
84-
imagettftext($canvas, $text_size, 0, 90, 82, $color, $text_fonts, $teamscores);//总积分
85-
//---------------------------------------------------------------------//
86-
//个人部分
87-
imagettftext($canvas, $text_size, 0, 280, 13, $color, $text_fonts, $name);//用户名
88-
imagettftext($canvas, $text_size, 0, 290, 32, $color, $text_fonts, $rank);//用户排名
89-
imagettftext($canvas, $text_size, 0, 300, 50, $color, $text_fonts, $wus);//已完成任务
90-
imagettftext($canvas, $text_size, 0, 280, 68, $color, $text_fonts, $scores);//总积分
91-
imagettftext($canvas, $text_size, 0, 310, 82, $color, $text_fonts, $lastwus);//最近一次完成
92-
//---------------------------------------------------------------------//
93-
header("content-type:image/png");//设置网页为图片
94-
imagepng($canvas);//输出图片
95-
imagedestroy($canvas);//关闭进程
96-
//---------------------------------------------------------------------//
69+
if($_GET['mode'] == 'advanced'){//判断是否是高级模式
70+
if($_GET['donor'] == null){
71+
echo '{"error": "10001"}';
72+
}elseif($_GET['team'] == null){
73+
echo '{"error": "10001"}';
74+
}else{
75+
if($_GET['height'] == null){//判断是否有提交画布大小
76+
if($_GET['weight'] == null){
77+
$canvas = imagecreatetruecolor(465, 92);//载入默认画布
78+
$weight = 465;
79+
$height = 95;
80+
$weightdefault = 465;
81+
$heightdefault = 95;
82+
}else{
83+
$error = 10001;
84+
}
85+
}elseif($_GET['weight'] == null){
86+
if($_GET['height'] == null){
87+
$canvas = imagecreatetruecolor(465, 92);//载入默认画布
88+
$weight = 465;
89+
$height = 95;
90+
$weightdefault = 465;
91+
$heightdefault = 95;
92+
}else{
93+
$error = 10001;
94+
}
95+
}else{
96+
$canvas = imagecreatetruecolor($_GET['weight'], $_GET['height']);//根据提交的参数载入画布
97+
$weightdefault = $_GET['weight'];
98+
$heightdefalut = $_GET['height'];
99+
}
100+
$background = imagecolorallocatealpha($canvas, 0, 0, 0, 127);//设置背景色
101+
imagefill($canvas, 0, 0, $background);//填充透明色
102+
imagecolortransparent($canvas, $background);//设置背景色
103+
if($_GET['fnt'] == null){//判断是否有提交自定义字体
104+
$text_fonts = 'fnt/default.ttf';//设置默认字体
105+
}else{
106+
$text_fonts = 'fnt/'.$_GET['fnt'];//根据提交的字体地址载入自定义字体
107+
}
108+
if($_GET['red'] == null){//判断是否有提交自定义字体颜色
109+
if($_GET['green'] == null){
110+
if($_GET['blue'] == null){
111+
$color = imagecolorallocate($canvas, 255, 255, 255);//设置默认文字颜色
112+
}else{
113+
$error = 10001;
114+
}
115+
}else{
116+
$error = 10001;
117+
}
118+
}else{
119+
if($_GET['green'] == null){
120+
}else{
121+
if($_GET['blue'] == null){
122+
}else{
123+
$color = imagecolorallocate($canvas, $_GET['red'], $_GET['green'], $_GET['blue']);//设置自定义文字颜色
124+
}
125+
}
126+
}
127+
if($_GET['textsize'] == null){//判断是否有提交自定义字体
128+
$text_size = 7;//设置默认字体大小
129+
}else{
130+
$text_size = $_GET['textsize'];//设置自定义字体大小
131+
}
132+
if($_GET['img'] == null){//判断是否有提交自定义底图
133+
$logo_url = 'img.png';//设置默认源图片
134+
}else{
135+
$logo_url = $_GET['img'];//设置自定义源图片
136+
}
137+
$logo = file_get_contents($logo_url);//读取源文件
138+
$logo_img = imagecreatefromstring($logo);//解析为图片
139+
if($_GET['imgx'] == null){//判断是否有提交自定义底图位置
140+
if($_GET['imgy'] == null){
141+
$imgx = 0;//设置默认底图位置
142+
$imgy = 0;
143+
}else{
144+
$error = 10001;
145+
}
146+
}else{
147+
if($_GET['imgy'] == null){
148+
$error = 10001;
149+
}else{
150+
$imgx = $_GET['imgx'];//设置自定义底图位置
151+
$imgy = $_GET['imgy'];
152+
}
153+
}
154+
if($_GET['putweight'] == null){
155+
if($_GET['putheight'] == null){
156+
$weight = $weightdefault;
157+
$height = $heightdefault;
158+
}else{
159+
$error = 10001;
160+
}
161+
}else{
162+
if($_GET['putheight'] == null){
163+
$error = 10001;
164+
}else{
165+
$weight = $_GET['putweight'];
166+
$height = $_GET['putheight'];
167+
}
168+
}
169+
imagecopyresampled($canvas, $logo_img, $imgx, $imgy, 0, 0, $weight, $height, imagesx($logo_img), imagesy($logo_img));//覆盖图层
170+
//---------------------------------------------------------------------//
171+
//团队部分
172+
imagettftext($canvas, $text_size, 0, 90, 13, $color, $text_fonts, $teamname);//团队名称
173+
imagettftext($canvas, $text_size, 0, 100, 30, $color, $text_fonts, $teamid);//团队编号
174+
imagettftext($canvas, $text_size, 0, 100, 48, $color, $text_fonts, $teamrank);//团队排名
175+
imagettftext($canvas, $text_size, 0, 110, 65, $color, $text_fonts, $teamwus);//已完成的任务
176+
imagettftext($canvas, $text_size, 0, 90, 82, $color, $text_fonts, $teamscores);//总积分
177+
//---------------------------------------------------------------------//
178+
//个人部分
179+
imagettftext($canvas, $text_size, 0, 280, 13, $color, $text_fonts, $name);//用户名
180+
imagettftext($canvas, $text_size, 0, 290, 32, $color, $text_fonts, $rank);//用户排名
181+
imagettftext($canvas, $text_size, 0, 300, 50, $color, $text_fonts, $wus);//已完成任务
182+
imagettftext($canvas, $text_size, 0, 280, 68, $color, $text_fonts, $scores);//总积分
183+
imagettftext($canvas, $text_size, 0, 310, 82, $color, $text_fonts, $lastwus);//最近一次完成
184+
//---------------------------------------------------------------------//
185+
if($error == null){//判断是否有错误
186+
header("content-type:image/png");//设置网页为图片
187+
imagepng($canvas);//输出图片
188+
imagedestroy($canvas);//关闭进程
189+
}elseif($error == 10001){
190+
echo '{"error": "10001"}';
191+
}
192+
}
193+
}else{
194+
if($_GET['donor'] == null){
195+
echo '{"error": "10001"}';
196+
}elseif($_GET['team'] == null){
197+
echo '{"error": "10001"}';
198+
}else{
199+
$canvas = imagecreatetruecolor(465, 92);//载入画布
200+
$background = imagecolorallocatealpha($canvas, 0, 0, 0, 127);//设置背景色
201+
imagefill($canvas, 0, 0, $background);//填充透明色
202+
imagecolortransparent($canvas, $background);//设置背景色
203+
$text_fonts = 'fnt/default.ttf';//设置字体
204+
$color = imagecolorallocate($canvas, 255, 255, 255);//设置文字颜色
205+
$text_size = 7;//设置文字大小
206+
$logo_url = 'img.png';//设置源图片目录
207+
$logo = file_get_contents($logo_url);//读取源文件
208+
$logo_img = imagecreatefromstring($logo);//解析为图片
209+
imagecopyresampled($canvas, $logo_img, 0, 0, 0, 0, 465, 92, imagesx($logo_img), imagesy($logo_img));//覆盖图层
210+
//---------------------------------------------------------------------//
211+
//团队部分
212+
imagettftext($canvas, $text_size, 0, 90, 13, $color, $text_fonts, $teamname);//团队名
213+
imagettftext($canvas, $text_size, 0, 100, 30, $color, $text_fonts, $teamid);//团队编号
214+
imagettftext($canvas, $text_size, 0, 100, 48, $color, $text_fonts, $teamrank);//团队排名
215+
imagettftext($canvas, $text_size, 0, 110, 65, $color, $text_fonts, $teamwus);//已完成的任务
216+
imagettftext($canvas, $text_size, 0, 90, 82, $color, $text_fonts, $teamscores);//总积分
217+
//---------------------------------------------------------------------//
218+
//个人部分
219+
imagettftext($canvas, $text_size, 0, 280, 13, $color, $text_fonts, $name);//用户名
220+
imagettftext($canvas, $text_size, 0, 290, 32, $color, $text_fonts, $rank);//用户排名
221+
imagettftext($canvas, $text_size, 0, 300, 50, $color, $text_fonts, $wus);//已完成任务
222+
imagettftext($canvas, $text_size, 0, 280, 68, $color, $text_fonts, $scores);//总积分
223+
imagettftext($canvas, $text_size, 0, 310, 82, $color, $text_fonts, $lastwus);//最近一次完成
224+
//---------------------------------------------------------------------//
225+
header("content-type:image/png");//设置网页为图片
226+
imagepng($canvas);//输出图片
227+
imagedestroy($canvas);//关闭进程
228+
}
229+
}

0 commit comments

Comments
 (0)