-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 1.0.0 Added default texture render backend inside 'backend/' Removed some debugging states from 'start.py' Tags can now use the full cape size for more flexibility. Updated tag textures for 'us.mineplex.com' to support this.
- Loading branch information
1 parent
293ee0a
commit c2fa933
Showing
33 changed files
with
184 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
// Get Crafatar from API | ||
class Crafatar { | ||
|
||
public function __construct($username,$scale) { | ||
$this->uuid = $this->getPlayerUUID($username); | ||
$this->url = "https://crafatar.com/renders/body/{$this->uuid}?scale={$scale}"; | ||
|
||
$this->data = $this->curl(); | ||
$this->image = imagecreatefromstring($this->data); | ||
$this->size = [imagesx($this->image),imagesy($this->image)]; | ||
} | ||
|
||
// Get player UUID from username | ||
private function getPlayerUUID($username) { | ||
$url = "https://playerdb.co/api/player/minecraft/"; | ||
|
||
$api = json_decode(file_get_contents($url.$username)); | ||
return $api->data->player->id; | ||
} | ||
|
||
private function curl() { | ||
$curl = curl_init(); | ||
|
||
curl_setopt($curl, CURLOPT_URL, $this->url); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // good edit, thanks! | ||
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); // also, this seems wise considering output is image. | ||
|
||
$data = curl_exec($curl); | ||
curl_close($curl); | ||
|
||
return $data; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
// Get Minotar from API | ||
class Minotar { | ||
|
||
public function __construct($username,$size) { | ||
$this->url = "https://minotar.net/armor/bust/{$username}/{$size}.png"; | ||
|
||
$this->data = $this->curl(); | ||
$this->image = imagecreatefromstring($this->data); | ||
$this->size = [imagesx($this->image),imagesy($this->image)]; | ||
} | ||
|
||
private function curl() { | ||
$curl = curl_init(); | ||
|
||
curl_setopt($curl, CURLOPT_URL, $this->url); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // good edit, thanks! | ||
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); // also, this seems wise considering output is image. | ||
|
||
$data = curl_exec($curl); | ||
curl_close($curl); | ||
|
||
return $data; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
// Add horizontally centered text at x,y | ||
class TextLayer { | ||
|
||
public function __construct($text,$font,$size) { | ||
$this->text = $text; | ||
$this->font = $font; | ||
|
||
$this->size = $this->scaleFont($text,$size); | ||
$this->setFontPath(); | ||
} | ||
|
||
// Prevent default GD font lookup path from being used | ||
private function setFontPath() { | ||
putenv("GDFONTPATH=".realpath("./".$this->font)); | ||
} | ||
|
||
// Calculate scaled front size from max-width | ||
private function scaleFont($text,$baseline) { | ||
$len = strlen($this->text); | ||
|
||
$log = $len / 0.6; | ||
$size = $baseline - $log; | ||
|
||
return $size; | ||
} | ||
|
||
// Center text | ||
private function offsetX($x) { | ||
$len = strlen($this->text); | ||
|
||
$offset = $x - ($len * ($this->size / 2.2)); | ||
|
||
return $offset; | ||
} | ||
|
||
// Image resource, x, y | ||
public function textcopy($image,$x,$y,$color) { | ||
imagettftext($image,$this->size,0,$this->offsetX($x),$y,$color,"font",$this->text); | ||
return true; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
require "classes/Minotar.php"; // Player avatar | ||
require "classes/TextLayer.php"; | ||
|
||
// Main class | ||
class Texture { | ||
|
||
public function __construct() { | ||
$this->input = [ | ||
"server" => $_GET["server"], | ||
"username" => $_GET["username"], | ||
"tag" => $_GET["tag"].".png" | ||
]; | ||
|
||
$this->path = "servers/{$this->input["server"]}/"; | ||
|
||
$this->validate(); | ||
} | ||
|
||
// Make sure all required urlparams are set | ||
private function validate() { | ||
foreach($this->input as $key => $value) { | ||
if(!$value) { | ||
$error[] = "Missing urlparam: '{$key}'."; | ||
} | ||
} | ||
|
||
if($error) { | ||
http_response_code("400 Bad Request"); | ||
echo implode(" ",$error); | ||
die(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// Create a new texture | ||
function create($x,$y) { | ||
// Layers | ||
$bg = imagecreatefrompng($this->path."bg.png"); | ||
$player = new Minotar($this->input["username"],100); | ||
$name = new TextLayer($this->input["username"],$this->path,30); | ||
$tag = imagecreatefrompng($this->path."tags/".$this->input["tag"]); | ||
|
||
// Create texture | ||
$image = imagecreatetruecolor($x,$y); | ||
$alpha = imagecolorallocatealpha($image,0,0,0,127); | ||
$color = imagecolorallocate($image,255,255,255); | ||
|
||
// Preserve transparency | ||
imagefill($image,0,0,$alpha); | ||
imagesavealpha($image,true); | ||
|
||
// Blend layers | ||
imagecopy($image,$bg,0,0,0,0,$x,$y); // Background | ||
imagecopy($image,$player->image,45,60,0,0,$player->size[0],$player->size[1]); // Player avatar | ||
$name->textcopy($image,110,210,$color); // Player name | ||
imagecopy($image,$tag,0,0,0,0,$x,$y); // Player rank | ||
|
||
// Output image | ||
header("Content-Type: image/png"); | ||
echo imagepng($image);; | ||
} | ||
|
||
} | ||
|
||
$texture = new Texture(); | ||
$texture->create(355,275); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters