Advertisement
Guest User

head.php

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