jlhaslip 4 Report post Posted October 8, 2007 In case you haven't noticed, I have a different Avatar display on the Forum each time the page is refreshed. For those of you who might want the script to do that, here is the one I am using: < ? php // lose the spaces $filesp = glob('*.png'); if(empty($filesp)){ echo 'no images found...die<br>'; die(); } else{ foreach ($filesp as $file) { $img_array[] = trim($file); } } shuffle($img_array); //select image at random header("C o n t e n t{dash}t y p e: image/png"); // replace the {dash} and lose the spaces $image = $img_array[0]; $image = imagecreatefrompng( "$image" ); imagepng($image); imagedestroy($image); ?> How the script works $filesp = glob('*.png');if(empty($filesp)){echo 'no images found...die<br>';die();} The png files are found and stored into a variable using the glob function by matching the last four characters of the filename.I there are no png files found, the script dies. foreach ($filesp as $file) {$img_array[] = trim($file); }}shuffle($img_array); //select image at random The loop stores the file names into an array which is then shuffled to randomize the list. header("C o n t e n t{dash}t y p e: image/png"); // replace the {dash} and lose the spaces$image = $img_array[0];$image = imagecreatefrompng( "$image" );imagepng($image);imagedestroy($image); The header for the file type png is output to tell the receiving Bowser what to expect, then the first element of the array is chosen for creation, and the image is output and destroyed. Implementation Save this script as a file named index.php. Place the index.php file into a folder named image.png (yes, that's correct) and load all the png format Avatars into the same folder. The images must be png files for this to work properly. Call the script using http://forums.xisto.com/no_longer_exists/ as the name of the image you want to display and the script finds all the png files in the folder, shuffles them up and spits out the first one in the list. How cool is that??? In order for this to work, you need a Hosting space that allows php code and a method to upload the files and images. You can use any size of image that you want, but many Forums only allow a 90 px x 90 px size, so I would stick to that size for the images. And restrict the number of images so the script runs quicker, too. Pre-size the png's to the size you need, like 90px x 90px, so the Server doesn't have to re-size them. Irfanview is a free download and includes a Batch Convertor that will change your existing images to png and resize them at the same time. Highly recommended. And if you need this as a jpg or gif based script, let me know... I might even make a multi-format version... Share this post Link to post Share on other sites