Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Usage: body.php?nick=Notch&size=4
- * Dimensions will be 16*size px width and 32*size px height
- */
- if(!isset($_GET['nick'])) {
- $_GET['nick'] = 'char';
- }
- if(!isset($_GET['size'])) {
- $_GET['size'] = 1;
- }
- $cache_file = 'cache_body/'.$_GET['nick'].'_'.$_GET['size'].'.png';
- $cache_life = '86400';
- $filemtime = @filemtime($cache_file);
- if (!$filemtime or (time() - $filemtime >= $cache_life)) {
- $width = 16*$_GET['size'];
- $height = 32*$_GET['size'];
- $img=imagecreatetruecolor(16,32);
- imagealphablending($img, false);
- $transparent = imagecolorallocatealpha($img, 0, 0, 0, 127);
- imagefill($img, 0, 0, $transparent);
- imagesavealpha($img,true);
- imagealphablending($img, true);
- $im = @imagecreatefrompng('http://s3.amazonaws.com/MinecraftSkins/'.$_GET['nick'].'.png');
- if(!$im) {
- $im = @imagecreatefrompng('http://s3.amazonaws.com/MinecraftSkins/char.png');
- }
- imagealphablending($im, true);
- imagecopy($img, $im, 4, 0, 8, 8, 8, 8); //head
- imagecopy($img, $im, 4, 8, 20, 20, 8, 12); //chest
- imagecopy($img, $im, 4, 20, 4, 20, 4, 12); //left leg
- imagecopyresampled($img, $im, 8, 20, 7, 20, 4, 12, -4, 12); //right leg (horizontal flipped left leg)
- imagecopy($img, $im, 0, 8, 44, 20, 4, 12); //left arm
- imagecopyresampled($img, $im, 12, 8, 47, 20, 4, 12, -4, 12); //right arm
- $resized=imagecreatetruecolor($width,$height);
- imagealphablending($resized, false);
- $transparent = imagecolorallocatealpha($resized, 0, 0, 0, 127);
- imagefill($resized, 0, 0, $transparent);
- imagesavealpha($resized,true);
- imagealphablending($resized, true);
- imagecopyresampled($resized, $img, 0, 0, 0, 0, $width, $height, 16, 32);
- header("Content-type: image/png");
- imagepng($resized);
- imagepng($resized, $cache_file);
- imagedestroy($img);
- imagedestroy($im);
- imagedestroy($bg);
- imagedestroy($resized);
- } else {
- readfile($cache_file);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement