Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@robske110
Forked from jasonw4331/PngToPlayer.php
Last active August 13, 2020 22:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robske110/5f93a00b2dee86b83497c437edfe4451 to your computer and use it in GitHub Desktop.
Save robske110/5f93a00b2dee86b83497c437edfe4451 to your computer and use it in GitHub Desktop.
Set a player's skin in PMMP
<?php
$path = 'your/path/to/skin.png';
$img = @imagecreatefrompng($path);
$bytes = '';
$l = (int) @getimagesize($path)[1];
for ($y = 0; $y < $l; $y++) {
for ($x = 0; $x < 64; $x++) {
$rgba = @imagecolorat($img, $x, $y);
$a = ((~((int)($rgba >> 24))) << 1) & 0xff;
$r = ($rgba >> 16) & 0xff;
$g = ($rgba >> 8) & 0xff;
$b = $rgba & 0xff;
$bytes .= chr($r) . chr($g) . chr($b) . chr($a);
}
}
@imagedestroy($img);
/** @var pocketmine\Player $player */
$player->setSkin(new pocketmine\entity\Skin("Standard_CustomSlim", $bytes)); //Standard_CustomSlim for alex
$player->sendSkin();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment