Skip to content

Convert skin or cape from png to config

ace edited this page May 31, 2023 · 4 revisions
  1. Copy the below script and save as skin.php
  2. Copy png files to the same directory as the script
  3. Execute the script php skin.php
  4. It will create a text file for each png file
  5. Copy contents of text file(s) into config Skin Data field
<?php
function toHex($img) : string {
	$bytes = "";
	for ($y = 0; $y < imagesy($img); $y++) {
		for ($x = 0; $x < imagesx($img); $x++) {
			$rgba = @imagecolorat($img, $x, $y);
			$a = ((~($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);
	return bin2hex($bytes);
}
foreach(new IteratorIterator(new DirectoryIterator(".")) as $fileInfo)
	if(strtolower($fileInfo->getExtension()) === "png")
		file_put_contents($fileInfo->getBasename().".txt",toHex(imagecreatefrompng($fileInfo->getBasename())));
Clone this wiki locally