Icy Phoenix

     
 



Post new topic  Reply to topic 
Page 1 of 1
 
 
Reply with quote Download Post 
Post Random Background Changer 
 
Here is a very basic script which will allow you to select a random image from all the images in a folder to be used as random background (for example) for your website.

First of all let me provide an example for you:

Random Background

If you click the link above and then refresh the target page you will see that the image will change each time (one among all the images in the folder will be selected).

I use that script to change the header of my website, so each page will have a different header background:
Annunci Di Matrimonio

How to achieve that?

It is really easy.

  1. Create a folder on your website and put all images you want to rotate (this script is based upon JPG images, but it won't be tough to be adapted to other images).
  2. Create a php file (choose the name you like... random_bg.php for example) with this code in it:
    Code: [Download] [Hide] [Select]
    <?php
    $img_array
    = array('bg_01.jpg', 'bg_02.jpg', 'bg_03.jpg', 'bg_04.jpg', 'bg_05.jpg', 'bg_06.jpg', 'bg_07.jpg', 'bg_08.jpg', 'bg_09.jpg');

    $img_rnd = rand(0, sizeof($img_array) - 1);

    header('Content-type: image/jpg');
    header('Content-Disposition: filename=' . $img_array[$img_rnd]);
    readfile($img_array[$img_rnd]);
    ?>

  3. Make sure the array at the beginning of the file contains all the images you want to rotate:
    Code: [Download] [Hide] [Select]
    $img_array = array('bg_01.jpg', 'bg_02.jpg', 'bg_03.jpg', 'bg_04.jpg', 'bg_05.jpg', 'bg_06.jpg', 'bg_07.jpg', 'bg_08.jpg', 'bg_09.jpg');

  4. Just recall the php file from your browser to test it (this is just an example):
    Code: [Download] [Hide] [Select]
    http://www.yoursite.com/images/random/random_bg.php

  5. If it is working fine, you can then use this image in your CSS or HTML code to output a random BG where needed!


I hope you will find this script useful!
 




____________
Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
 
Mighty GorgonSend private messageSend e-mail to userVisit poster's website  
Back to topPage bottom
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.

Support us
 
Reply with quote Download Post 
Post Re: Random Background Changer 
 
can you hear that funny clapping sound??? it 's me applauding     sh_06
 




____________
www.DutchaGoGo.com (development/under construction ...Forever?¿?)
 
Joshua203Send private messageVisit poster's website  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Random Background Changer 
 
Thanks MG, I think this is very usefull

 
 




____________
TheSteffen
Often SEARCH is the quickest way to get support.
IcyPhoenix German Support
 
TheSteffenSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Random Background Changer 
 
Thanks so much for posting this. It would be useful for this project that I have been working on. By the way, is it possible to embed the php coding into an html document? Please let me know. Thanks again.
 



 
cherylSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Random Background Changer 
 
What do you mean?

This modification doesn't need that, because you can create the php file and then include the image where needed by just using html.
 




____________
Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
 
Mighty GorgonSend private messageSend e-mail to userVisit poster's website  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Random Background Changer 
 
cheryl wrote: [View Post]
By the way, is it possible to embed the php coding into an html document? Please let me know. Thanks again.


If you mean embedding it directly into an html mime type - something.html etc the answer is no you can't.

You have to trick it by using more than one file. Usually a variable.php, something.php and something.html files.
 



 
mortSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Random Background Changer 
 
I had some questions at phpbb.com about this and think the next quote from that thread may help people that want to use this as a header background changer

Joshua203 wrote: 
cyanman85 wrote: 
Where do i put the folder with the images?

Try styles/milky_way/theme/images

cyanman85 wrote: 
Do I not have to make a path to the images folder in the php code? (It does not describe this).

No

cyanman85 wrote: 
Where do I put the php file I generate?

In the same folder as the images

Then you open the stylesheet.css with an editor (a good one ...not notepad) and find something that looks like this:
Code: [Download] [Hide]
  1. #top_logo{ 
  2.     border-width: 0px 0px 0px 0px; 
  3.     margin: 0px 0px 0px 0px; 
  4.     padding: 0px 0px 0px 0px; 
  5.     background: url('./images/top_header.png') repeat; 
  6.     height: 150px; 


Replace the line:
Code: [Download] [Hide]
  1.     background: url('./images/top_header.png') repeat; 

With:
Code: [Download] [Hide]
  1.     background: url('./images/YOUR FOLDER/random_bg.php') no-repeat; 


and post back how it looks

*Note... I've just tested this on black_pearl so the codes may differ a bit
BTW ...always backup the files before you edit them!!!


Greetings,
...Joshua203
 




____________
www.DutchaGoGo.com (development/under construction ...Forever?¿?)
 
Joshua203Send private messageVisit poster's website  
Back to topPage bottom
Post new topic  Reply to topic  Page 1 of 1
 


Display posts from previous:    

HideWas this topic useful?

Link this topic
URL
BBCode
HTML




 
Permissions List
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events


  

 

  cron