Skip to content

Commit 604590c

Browse files
committed
v2 update, tidy up codes and fixed api error
1 parent 83a1681 commit 604590c

File tree

6 files changed

+72
-234
lines changed

6 files changed

+72
-234
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
#### 安装教程
1111

12-
1. 配置任意编译环境
13-
2. 配置带有GD库的PHP7.2环境
12+
1. 下载字体并修改对应字体文件路径(推荐HarmonyOS Sans)
13+
2. 配置带有GD库的PHP8.1环境
1414
3. 设置站点
1515
4. 上传本项目的文件
16+
5. 访问调用
1617

1718

1819
#### 参与贡献

api.php

Lines changed: 0 additions & 232 deletions
This file was deleted.

backs/en_US.png

10.1 KB
Loading

img.png renamed to backs/zh_CN.png

File renamed without changes.

index.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
$DEBUG = false;
3+
$langs = array("zh_CN", "en_US");
4+
5+
if (!isset($_GET["donor"]) || !isset($_GET["team"])) {
6+
exit("empty field");
7+
}
8+
9+
if (!isset($_GET["lang"]) || !in_array($_GET["lang"], $langs)) {
10+
$lang = "zh_CN";
11+
} else {
12+
$lang = $_GET["lang"];
13+
}
14+
15+
// Get donor
16+
$donor = $_GET["donor"];
17+
18+
// Setting foor ssl
19+
$arr_context_options = array(
20+
"ssl" => array(
21+
"verify_peer" => false,
22+
"verify_peer_name" => false,
23+
"allow_self_signed" => true,
24+
) ,
25+
);
26+
27+
// Request for data
28+
$donor_data = file_get_contents("https://api.foldingathome.org/user/".$donor, false, stream_context_create($arr_context_options)) or die("api failed");
29+
$donor_object = json_decode($donor_data, true);
30+
if ($DEBUG) var_dump($donor_object);
31+
32+
$team_data = file_get_contents("https://api.foldingathome.org/team/".$_GET["team"], false, stream_context_create($arr_context_options)) or die("api failed");
33+
$team_object = json_decode($donor_data, true);
34+
if ($DEBUG) var_dump($team_object);
35+
36+
// Load canvas
37+
$canvas = imagecreatetruecolor(465, 92);
38+
// Set background color
39+
$background = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
40+
// Fill with TRN
41+
imagefill($canvas, 0, 0, $background);
42+
imagecolortransparent($canvas, $background);
43+
// Set font
44+
$text_fonts = 'fonts/HarmonyOS_Sans_SC_Bold.ttf'; // font
45+
$color = imagecolorallocate($canvas, 255, 255, 255); // color
46+
$text_size = 7; // size
47+
// Set background picture
48+
$logo_url = 'backs/'.$lang.'.png';
49+
$logo = file_get_contents($logo_url);
50+
$logo_img = imagecreatefromstring($logo);
51+
imagecopyresampled($canvas, $logo_img, 0, 0, 0, 0, 465, 92, imagesx($logo_img), imagesy($logo_img));
52+
53+
// For team
54+
imagettftext($canvas, $text_size, 0, 90, 13, $color, $text_fonts, $team_object["name"]); // name
55+
imagettftext($canvas, $text_size, 0, 100, 30, $color, $text_fonts, $team_object["id"]); // id
56+
imagettftext($canvas, $text_size, 0, 100, 48, $color, $text_fonts, $team_object["rank"]); // rank
57+
imagettftext($canvas, $text_size, 0, 110, 65, $color, $text_fonts, $team_object["wus"]); // wus
58+
imagettftext($canvas, $text_size, 0, 90, 82, $color, $text_fonts, $team_object["score"]); // score
59+
60+
// For donor
61+
imagettftext($canvas, $text_size, 0, 280, 13, $color, $text_fonts, $team_object["name"]); // name
62+
imagettftext($canvas, $text_size, 0, 290, 32, $color, $text_fonts, $team_object["rank"]); // rank
63+
imagettftext($canvas, $text_size, 0, 300, 50, $color, $text_fonts, $team_object["wus"]); // wus
64+
imagettftext($canvas, $text_size, 0, 280, 68, $color, $text_fonts, $team_object["score"]); // score
65+
imagettftext($canvas, $text_size, 0, 310, 82, $color, $text_fonts, $team_object["last"]); // last done
66+
67+
if (!$DEBUG) header("content-type:image/png");
68+
imagepng($canvas);
69+
imagedestroy($canvas);

请自行下载字体并命名为fnt.ttf

Whitespace-only changes.

0 commit comments

Comments
 (0)