Advertisement
Guest User

body.php

a guest
Nov 27th, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. <?php
  2.    
  3.     /*
  4.     *   Usage: body.php?nick=Notch&size=4
  5.     *   Dimensions will be 16*size px width and 32*size px height
  6.     */
  7.    
  8.     if(!isset($_GET['nick'])) {
  9.         $_GET['nick'] = 'char';
  10.     }
  11.     if(!isset($_GET['size'])) {
  12.         $_GET['size'] = 1;
  13.     }
  14.  
  15.     $cache_file = 'cache_body/'.$_GET['nick'].'_'.$_GET['size'].'.png';
  16.     $cache_life = '86400';
  17.     $filemtime = @filemtime($cache_file);
  18.    
  19.     if (!$filemtime or (time() - $filemtime >= $cache_life)) {
  20.        
  21.         $width = 16*$_GET['size'];
  22.         $height = 32*$_GET['size'];
  23.        
  24.         $img=imagecreatetruecolor(16,32);
  25.         imagealphablending($img, false);
  26.         $transparent = imagecolorallocatealpha($img, 0, 0, 0, 127);
  27.         imagefill($img, 0, 0, $transparent);
  28.         imagesavealpha($img,true);
  29.         imagealphablending($img, true);
  30.        
  31.         $im = @imagecreatefrompng('http://s3.amazonaws.com/MinecraftSkins/'.$_GET['nick'].'.png');
  32.         if(!$im) {
  33.             $im = @imagecreatefrompng('http://s3.amazonaws.com/MinecraftSkins/char.png');
  34.         }
  35.        
  36.         imagealphablending($im, true);
  37.         imagecopy($img, $im, 4, 0, 8, 8, 8, 8); //head
  38.         imagecopy($img, $im, 4, 8, 20, 20, 8, 12); //chest
  39.         imagecopy($img, $im, 4, 20, 4, 20, 4, 12); //left leg
  40.         imagecopyresampled($img, $im, 8, 20, 7, 20, 4, 12, -4, 12); //right leg (horizontal flipped left leg)
  41.         imagecopy($img, $im, 0, 8, 44, 20, 4, 12); //left arm
  42.         imagecopyresampled($img, $im, 12, 8, 47, 20, 4, 12, -4, 12); //right arm
  43.    
  44.         $resized=imagecreatetruecolor($width,$height);
  45.         imagealphablending($resized, false);
  46.         $transparent = imagecolorallocatealpha($resized, 0, 0, 0, 127);
  47.         imagefill($resized, 0, 0, $transparent);
  48.         imagesavealpha($resized,true);
  49.         imagealphablending($resized, true);
  50.        
  51.         imagecopyresampled($resized, $img, 0, 0, 0, 0, $width, $height, 16, 32);
  52.        
  53.         header("Content-type: image/png");
  54.  
  55.         imagepng($resized);
  56.         imagepng($resized, $cache_file);
  57.         imagedestroy($img);
  58.         imagedestroy($im);
  59.         imagedestroy($bg);
  60.         imagedestroy($resized);    
  61.     } else {   
  62.         readfile($cache_file); 
  63.     }
  64.        
  65. ?>
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement