|
Page 1 of 1
|
Mighty Gorgon 
Luca Libralato
Joined: August 2006
Posts: 7192
Location:  Borgo San Michele
|
 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.
- 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).
- Create a php file (choose the name you like... random_bg.php for example) with this code in it:
<?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]); ?>
- Make sure the array at the beginning of the file contains all the images you want to rotate:
$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');
- Just recall the php file from your browser to test it (this is just an example):
http://www.yoursite.com/images/random/random_bg.php
- 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
|
#1 Tue 25 May, 2010 21:02 |
|
Sponsors

|
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.
|
|
Joshua203 
Joshua 203
Dutch A Go Go

Joined: August 2008
Posts: 1754
Location:  Earth, Europe, the Netherlands, Rotterdam
|
 Re: Random Background Changer
can you hear that funny clapping sound??? it 's me applauding
____________ www.DutchaGoGo.com (development/under construction ...Forever?¿?)
|
#2 Tue 25 May, 2010 21:26 |
|
TheSteffen 
Joined: August 2006
Posts: 1625
Location:  Magdeburg
|
 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
|
#3 Thu 03 Jun, 2010 09:39 |
|
cheryl 
Joined: September 2011
Posts: 1
|
 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.
|
#4 Fri 09 Sep, 2011 08:26 |
|
Mighty Gorgon 
Luca Libralato
Joined: August 2006
Posts: 7192
Location:  Borgo San Michele
|
 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
|
#5 Tue 13 Sep, 2011 00:12 |
|
mort 
 Spam Basher

Joined: August 2010
Posts: 998
Location:  Up a tree
|
 Re: Random Background Changer
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.
|
#6 Tue 13 Sep, 2011 02:22 |
|
Joshua203 
Joshua 203
Dutch A Go Go

Joined: August 2008
Posts: 1754
Location:  Earth, Europe, the Netherlands, Rotterdam
|
 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:
- #top_logo{
- border-width: 0px 0px 0px 0px;
- margin: 0px 0px 0px 0px;
- padding: 0px 0px 0px 0px;
- background: url('./images/top_header.png') repeat;
- height: 150px;
- }
Replace the line:
- background: url('./images/top_header.png') repeat;
With:
- 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?¿?)
|
#7 Tue 13 Sep, 2011 16:28 |
|
|
Page 1 of 1
|
Was this topic useful?
Was this topic useful?
Link this topic |
URL |
|
BBCode |
|
HTML |
|
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
|
|
|
|