个人手札:PHP 從 Minecraft 皮肤文件中获取头像

// 此处以 Skinme 皮肤站的皮肤为例
$skin = "http://www.skinme.cc/uniskin/textures/{$id}";
$skin = file_get_contents($skin);
$im = imagecreatefromstring($skin);
$size = 300; // 头像尺寸
$view = 'f'; // 视角方向
// f: 正面
// b: 背面(后脑勺)
// l: 左侧
// r: 右侧
$av = imagecreatetruecolor($size, $size);
$x = array('f' => 8, 'l' => 16, 'r' => 0, 'b' => 24);

// 裁剪头像
imagecopyresized($av, $im, 0, 0, $x[$view], 8, $size, $size, 8, 8);
// 修复 BUG
imagecolortransparent($im, imagecolorat($im, 63, 0));
// 添加头饰
imagecopyresized($av, $im, 0, 0, $x[$view] + 32, 8, $size, $size, 8, 8);

header('Content-type: image/png');
imagepng($av);
imagedestroy($im);
imagedestroy($av);
exit();
本作品采用《CC 协议》,转载必须注明作者和本文链接
sunxyw
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!