Code : PHP: public function getSkin(string $fileName) : ?Skin{ $path = $this->getDataFolder() . "skins" . DIRECTORY_SEPARATOR . $fileName . ".png"; if(!is_file($path)){ return null; } $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); } }
You must enable GD2 extension from php.ini. İf you use linux you must compile GD2 extension. Windows: Code: extension=php_gd2.dll Linux: Code: ./compile.sh -d compile.sh in github github.com/pmmp/php-build-scripts/