本文整理匯總了PHP中pocketmine\entity\Human::getSkinData方法的典型用法代碼示例。如果您正苦於以下問題:PHP Human::getSkinData方法的具體用法?PHP Human::getSkinData怎麽用?PHP Human::getSkinData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\entity\Human
的用法示例。
在下文中一共展示了Human::getSkinData方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: saveSkin
/**
* Save skin
* @param Human $human
* @param str $fn
* @param str $fmt
* @return int
*/
public static function saveSkin(Human $human, $fn, $fmt = self::AUTO_FMT)
{
if ($fmt === self::AUTO_FMT) {
$fmt = self::RAW_FMT;
if (self::isPngExt($fn)) {
$fmt = self::PNG_FMT;
}
}
if (extension_loaded("gd") && $fmt == self::PNG_FMT) {
$img = imagecreatetruecolor(64, 32);
// Allocate colors...
$colors = [];
$bytes = $human->getSkinData();
echo "BYTES=" . strlen($bytes) . "\n";
//##DEBUG
$x = $y = $c = 0;
while ($y < 32) {
$cid = substr($bytes, $c, 3);
if (!isset($colors[$cid])) {
$colors[$cid] = imagecolorallocate($img, ord($cid[0]), ord($cid[1]), ord($cid[2]));
}
imagesetpixel($img, $x, $y, $colors[$cid]);
$x++;
$c += 4;
if ($x === 64) {
$x = 0;
$y++;
}
}
echo "COLORS=" . count($colors) . "\n";
//##DEBUG
if (!imagepng($img, $fn)) {
imagedestroy($img);
return 0;
}
imagedestroy($img);
return filesize($fn);
}
$bin = zlib_encode($human->getSkinData(), ZLIB_ENCODING_DEFLATE, 9);
file_put_contents($fn, $bin);
return strlen($bin);
}
示例2: toFile
/**
* Creates a new file containing skin data
* @param Human $human
*/
public static function toFile(Human $human)
{
@mkdir(SkinTools::getInstance()->getDataFolder() . "data/");
file_put_contents(SkinTools::getInstance()->getDataFolder() . "data/" . strtolower($human->getName()) . ".dat", self::compress($human->getSkinData()));
}