|
| 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); |
0 commit comments