Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Random Avatar Generator
- * Based on GTAvatars by GTAGames.nl
- * Script by David22 for GTAGames.nl
- *
- */
- // Open the front directory en create an array with all png images in there
- $dir = opendir("./front");
- $fronts = array();
- while($filename = readdir($dir)) {
- if(pathinfo($filename, PATHINFO_EXTENSION) == "png") {
- $fronts[] = $filename;
- }
- }
- closedir($dir);
- // Perform the same action for the back directory
- $dir = opendir("./back");
- $backs = array();
- while($filename = readdir($dir)) {
- if(pathinfo($filename, PATHINFO_EXTENSION) == "png") {
- $backs[] = $filename;
- }
- }
- closedir($dir);
- // Choose a random index from the generated arrays
- $front = $fronts[array_rand($fronts)];
- $back = $backs[array_rand($backs)];
- // Tell the browser we're providing an image
- header('content-type: image/png');
- // The base will be the background
- $image = imagecreatefrompng("back/" . $back);
- // Open the foreground
- $overlay = imagecreatefrompng("front/" . $front);
- // Paste the foreground over the background
- imagecopy($image, $overlay, 0, 0, 0, 0, 512, 512);
- // Output the image
- imagepng($image);
- // Clear the buffer
- imagedestroy($image);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement