labylib-chattycape/backend/classes/Crafatar.php
Victor Westerlund c2fa933b3a 1.0.0
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.
2020-11-18 14:06:08 +01:00

36 lines
No EOL
981 B
PHP

<?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;
}
}