Skip to content

Commit

Permalink
v2 update, tidy up codes and fixed api error
Browse files Browse the repository at this point in the history
  • Loading branch information
bigsk05 committed Aug 19, 2022
1 parent 83a1681 commit 604590c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 234 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

#### 安装教程

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


#### 参与贡献
Expand Down
232 changes: 0 additions & 232 deletions api.php

This file was deleted.

Binary file added backs/en_US.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
69 changes: 69 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
$DEBUG = false;
$langs = array("zh_CN", "en_US");

if (!isset($_GET["donor"]) || !isset($_GET["team"])) {
exit("empty field");
}

if (!isset($_GET["lang"]) || !in_array($_GET["lang"], $langs)) {
$lang = "zh_CN";
} else {
$lang = $_GET["lang"];
}

// Get donor
$donor = $_GET["donor"];

// Setting foor ssl
$arr_context_options = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => true,
) ,
);

// Request for data
$donor_data = file_get_contents("https://api.foldingathome.org/user/".$donor, false, stream_context_create($arr_context_options)) or die("api failed");
$donor_object = json_decode($donor_data, true);
if ($DEBUG) var_dump($donor_object);

$team_data = file_get_contents("https://api.foldingathome.org/team/".$_GET["team"], false, stream_context_create($arr_context_options)) or die("api failed");
$team_object = json_decode($donor_data, true);
if ($DEBUG) var_dump($team_object);

// Load canvas
$canvas = imagecreatetruecolor(465, 92);
// Set background color
$background = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
// Fill with TRN
imagefill($canvas, 0, 0, $background);
imagecolortransparent($canvas, $background);
// Set font
$text_fonts = 'fonts/HarmonyOS_Sans_SC_Bold.ttf'; // font
$color = imagecolorallocate($canvas, 255, 255, 255); // color
$text_size = 7; // size
// Set background picture
$logo_url = 'backs/'.$lang.'.png';
$logo = file_get_contents($logo_url);
$logo_img = imagecreatefromstring($logo);
imagecopyresampled($canvas, $logo_img, 0, 0, 0, 0, 465, 92, imagesx($logo_img), imagesy($logo_img));

// For team
imagettftext($canvas, $text_size, 0, 90, 13, $color, $text_fonts, $team_object["name"]); // name
imagettftext($canvas, $text_size, 0, 100, 30, $color, $text_fonts, $team_object["id"]); // id
imagettftext($canvas, $text_size, 0, 100, 48, $color, $text_fonts, $team_object["rank"]); // rank
imagettftext($canvas, $text_size, 0, 110, 65, $color, $text_fonts, $team_object["wus"]); // wus
imagettftext($canvas, $text_size, 0, 90, 82, $color, $text_fonts, $team_object["score"]); // score

// For donor
imagettftext($canvas, $text_size, 0, 280, 13, $color, $text_fonts, $team_object["name"]); // name
imagettftext($canvas, $text_size, 0, 290, 32, $color, $text_fonts, $team_object["rank"]); // rank
imagettftext($canvas, $text_size, 0, 300, 50, $color, $text_fonts, $team_object["wus"]); // wus
imagettftext($canvas, $text_size, 0, 280, 68, $color, $text_fonts, $team_object["score"]); // score
imagettftext($canvas, $text_size, 0, 310, 82, $color, $text_fonts, $team_object["last"]); // last done

if (!$DEBUG) header("content-type:image/png");
imagepng($canvas);
imagedestroy($canvas);
Empty file.

0 comments on commit 604590c

Please sign in to comment.