Advertisement
Guest User

Untitled

a guest
May 27th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  *   Random Avatar Generator
  4.  *   Based on GTAvatars by GTAGames.nl
  5.  *   Script by David22 for GTAGames.nl
  6.  *
  7.  */
  8.  
  9. // Open the front directory en create an array with all png images in there
  10. $dir = opendir("./front");
  11. $fronts = array();
  12. while($filename = readdir($dir)) {
  13.     if(pathinfo($filename, PATHINFO_EXTENSION) == "png") {
  14.         $fronts[] = $filename;
  15.     }
  16. }
  17. closedir($dir);
  18.  
  19. // Perform the same action for the back directory
  20. $dir = opendir("./back");
  21. $backs = array();
  22. while($filename = readdir($dir)) {
  23.     if(pathinfo($filename, PATHINFO_EXTENSION) == "png") {
  24.         $backs[] = $filename;
  25.     }
  26. }
  27. closedir($dir);
  28.  
  29. // Choose a random index from the generated arrays
  30. $front =  $fronts[array_rand($fronts)];
  31. $back = $backs[array_rand($backs)];
  32.  
  33. // Tell the browser we're providing an image
  34. header('content-type: image/png');
  35.  
  36. // The base will be the background
  37. $image = imagecreatefrompng("back/" . $back);
  38.  
  39. // Open the foreground
  40. $overlay = imagecreatefrompng("front/" . $front);
  41.  
  42. // Paste the foreground over the background
  43. imagecopy($image, $overlay, 0, 0, 0, 0, 512, 512);
  44.  
  45. // Output the image
  46. imagepng($image);
  47.  
  48. // Clear the buffer
  49. imagedestroy($image);
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement