Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Image Rotator Script (another One), easy to implement
jlhaslip
post Oct 8 2007, 07:04 AM
Post #1


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 4,085
Joined: 24-July 05
From: Linix, DOS and Windows…the good, the bad and the ugly
Member No.: 9,787
Spam Patrol



In case you haven't noticed, I have a different Avatar display on the Forum each time the page is refreshed.

biggrin.gif

For those of you who might want the script to do that, here is the one I am using:

HTML
< ? 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

CODE
$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.

CODE
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.

CODE
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://your-domain/folder-path/image.png 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...

tongue.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Many Php Script Sites(16)
  2. Image Preloader With Progress Bar Status(23)
  3. [help] Java Script: Window.open(10)
  4. Web Surfing- Script Needed(2)
  5. Guestbook (cgi-script) Problems(5)
  6. A Pretty Good Easy Way To Make Some Money(21)
  7. Delay X Seconds In Flash(1)
  8. Verifying Email Addresses(9)
  9. How To Create Embed Image Mail In Gmail(56)
  10. Trap17 Link Exchange Script Introduced(28)
  11. Wmp (windows Media Photo) - The New Image File Format From Microsoft(33)
  12. I Need Recipes That Are Easy And Very Quick To Make(25)
  13. Real Paying Site(10)
  14. Jsp Or Java Chat Script Like Mig33(5)
  15. Registry Easy(6)
  1. Very Simple Online Now Script(4)
  2. Do You Use Imagefilez.com?(36)
  3. Adsense Earning Is Just Made Easy(3)
  4. Remembering Your Dreams(10)
  5. Easy Plants For Brown Thumbs(1)
  6. Easy Spicy Ranch Dip Recipe(4)
  7. [request] Avatar For Trap17 Users(0)
  8. Finding The Rgb Color Of An Image(3)
  9. Cash Lagoon(5)
  10. Java Script To Hide The Url In Address Bar(6)
  11. Testing Of The Auto Image Resizer(0)
  12. Need Help With Javascript Drag And Drop Script(2)
  13. Image Upload To Cutenews(2)


 



- Lo-Fi Version Time is now: 13th October 2008 - 07:20 PM