Skip to content

Commit 16a65fb

Browse files
Bigskgitee-org
authored andcommitted
Main Application
1 parent 4851b94 commit 16a65fb

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

api.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
//Copyright GHINK Network Studio.
3+
//LGPLv3.0
4+
//---------------------------------------------------------------------//
5+
$stream_opts = [
6+
"ssl" => [
7+
"verify_peer"=>false,
8+
"verify_peer_name"=>false,
9+
]
10+
]; //读取API JSON并转为数组
11+
$teamjson=file_get_contents("https://stats.foldingathome.org/api/team/".$_GET['teamid'],false, stream_context_create($stream_opts));
12+
$donorjson=file_get_contents("https://stats.foldingathome.org/api/donor/".$_GET['donor'],false, stream_context_create($stream_opts));
13+
$team=json_decode($teamjson, true);
14+
$donor=json_decode($donorjson, true);
15+
//---------------------------------------------------------------------//
16+
foreach ($team as $key => $value) { //遍历数组,读取数据
17+
if($key='name'){
18+
$teamname=$team['name'];
19+
}
20+
}
21+
foreach ($team as $key => $value) {
22+
if($key='team'){
23+
$teamid=$team['team'];
24+
}
25+
}
26+
foreach ($team as $key => $value) {
27+
if($key='rank'){
28+
$teamrank=$team['rank'];
29+
}
30+
}
31+
foreach ($team as $key => $value) {
32+
if($key='wus'){
33+
$teamwus=$team['wus'];
34+
}
35+
}
36+
foreach ($team as $key => $value) {
37+
if($key='credit'){
38+
$teamscores=$team['credit'];
39+
}
40+
}
41+
foreach ($donor as $key => $value) {
42+
if($key='name'){
43+
$name=$donor['name'];
44+
}
45+
}
46+
foreach ($donor as $key => $value) {
47+
if($key='rank'){
48+
$rank=$donor['rank'];
49+
}
50+
}
51+
foreach ($donor as $key => $value) {
52+
if($key='wus'){
53+
$wus=$donor['wus'];
54+
}
55+
}
56+
foreach ($donor as $key => $value) {
57+
if($key='credit'){
58+
$scores=$donor['credit'];
59+
}
60+
}
61+
foreach ($donor as $key => $value) {
62+
if($key='last'){
63+
$lastwus=$donor['last'];
64+
}
65+
}
66+
//---------------------------------------------------------------------//
67+
$canvas = imagecreatetruecolor(465, 92);//载入画布
68+
$background = imagecolorallocatealpha($canvas, 0, 0, 0, 127);//设置背景色
69+
imagefill($canvas, 0, 0, $background);//填充透明色
70+
imagecolortransparent($canvas, $background);//设置背景色
71+
$dir = dirname(__FILE__).'\\';//取得运行目录
72+
$text_fonts = $dir.'fnt.ttf';//设置字体
73+
$color = imagecolorallocate($canvas, 255, 255, 255);//设置文字颜色
74+
$text_size = 7;//设置文字大小
75+
$logo_url = $dir.'img.png';//设置源图片目录
76+
$logo = @file_get_contents($logo_url);//读取源文件
77+
$logo_img = imagecreatefromstring($logo);//解析为图片
78+
imagecopyresampled($canvas, $logo_img, 0, 0, 0, 0, 465, 92, imagesx($logo_img), imagesy($logo_img));//覆盖图层
79+
//---------------------------------------------------------------------//
80+
//团队部分
81+
imagettftext($canvas, $text_size, 0, 90, 13, $color, $text_fonts, $teamname);//团队名
82+
imagettftext($canvas, $text_size, 0, 100, 30, $color, $text_fonts, $teamid);//团队编号
83+
imagettftext($canvas, $text_size, 0, 100, 48, $color, $text_fonts, $teamrank);//团队排名
84+
imagettftext($canvas, $text_size, 0, 110, 65, $color, $text_fonts, $teamwus);//已完成的任务
85+
imagettftext($canvas, $text_size, 0, 90, 82, $color, $text_fonts, $teamscores);//总积分
86+
//---------------------------------------------------------------------//
87+
//个人部分
88+
imagettftext($canvas, $text_size, 0, 280, 13, $color, $text_fonts, $name);//用户名
89+
imagettftext($canvas, $text_size, 0, 290, 32, $color, $text_fonts, $rank);//用户排名
90+
imagettftext($canvas, $text_size, 0, 300, 50, $color, $text_fonts, $wus);//已完成任务
91+
imagettftext($canvas, $text_size, 0, 280, 68, $color, $text_fonts, $scores);//总积分
92+
imagettftext($canvas, $text_size, 0, 310, 82, $color, $text_fonts, $lastwus);//最近一次完成
93+
//---------------------------------------------------------------------//
94+
header("content-type:image/png");//设置网页为图片
95+
imagepng($canvas);//输出图片
96+
imagedestroy($canvas);//关闭进程
97+
//---------------------------------------------------------------------//

img.png

10.3 KB
Loading

0 commit comments

Comments
 (0)