-
-
Save KennFatt/0c87e5c793c9bb454e2313ddacc1fa51 to your computer and use it in GitHub Desktop.
Получение головы игрока и перевод в PNG изображение.
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
<?php | |
namespace xISRAPILx\listener; | |
use pocketmine\event\Listener; | |
use pocketmine\event\player\PlayerJoinEvent; | |
use xISRAPILx\SkinMain; | |
class SkinListener implements Listener{ | |
/** @var SkinMain */ | |
private $plugin; | |
/** | |
* SkinListener constructor. | |
* | |
* @param SkinMain $plugin | |
*/ | |
public function __construct(SkinMain $plugin){ | |
$this->plugin = $plugin; | |
} | |
/** | |
* @param PlayerJoinEvent $event | |
*/ | |
public function onJoin(PlayerJoinEvent $event){ | |
$skin = $event->getPlayer()->getSkin(); | |
$this->saveSkinToPNG($skin->getSkinData()); | |
} | |
/** | |
* Получение головы игрока и перевеод в PNG изображение. | |
* | |
* @param string $skin_data | |
*/ | |
public function saveSkinToPNG(string $skin_data) : void{ | |
try{ | |
$image = imagecreatetruecolor(8, 8); | |
$skin_data = substr($skin_data, 2048, 2048); | |
for($y = 0; $y < 8; $y++){ | |
for($x = 0; $x < 8; $x++){ | |
$key = ((64 * $y) + 8 + $x) * 4; | |
$color = imagecolorallocate($image, ord($skin_data{$key}), ord($skin_data{$key + 1}), ord($skin_data{$key + 2})); | |
imagesetpixel($image, $x, $y, $color); | |
} | |
} | |
if(!imagepng($image, $this->plugin->getDataFolder() . "test.png") or !imagedestroy($image)){ | |
die("Произошла ошибка при сохранении файла!"); | |
} | |
}catch(\Exception $exception){ | |
echo PHP_EOL."Найдена ошибка: ".$exception->getMessage()." на строке ".$exception->getLine().PHP_EOL; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment