https://www.icyphoenix.com/viewtopic.php?f=32&t=6837
-----------------------------------
Crocodile
Sat 09 Jan, 2010 22:07

Alternating Random Background Images
-----------------------------------
I am using Rainbow Pearl and Black Pearl in my new forum but would like to alternate the background image in the header.  I have tried adapting what I have read to suit but without success.

Is this even possible?

Thank you


-----------------------------------
Joshua203
Sat 16 Jan, 2010 00:18

Re: Alternating Random Background Images
-----------------------------------
hi i use black pearl, can you clarify what you want to do exactly?


-----------------------------------
Crocodile
Sat 16 Jan, 2010 00:37

Re: Alternating Random Background Images
-----------------------------------
Sorry.  I guess I wasn't clear.

I am using a background image in the header of my site.  Check it out [url=http://www.topdriverboards.com]here.

I would like to alternate that image.  How do I do it?

thanks


-----------------------------------
Joshua203
Sat 16 Jan, 2010 00:56

Re: Alternating Random Background Images
-----------------------------------
uuhm looking at that link i guess you have to replace site-logo-6.png


-----------------------------------
Mighty Gorgon
Sun 17 Jan, 2010 11:00

Re: Alternating Random Background Images
-----------------------------------
I answered here:
http://www.phpbb.com/community/viewtopic.php?p=11772585#p11772585

[quote="Mighty Gorgon"]You should alter [b]top_header.png[/b] in stylesheet.css with the dynamically generated image.

[code]#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;
}[/code]

You need a dynamic image and there are several ways for doing that.

Usually you should code a php files which generate the images and then use directly the PHP files (with correct headers) or use an htaccess rule to redirect a PNG call to the PHP files.

So in a nutshell, here is a demo for a dynamic PHP image (supposing you have the JPG files listed in the array):
[code=php]<?php

$img_array = array('bkg_01.jpg', 'bkg_02.jpg', 'bkg_03.jpg', 'bkg_04.jpg', 'bkg_05.jpg', 'bkg_06.jpg', 'bkg_07.jpg', 'bkg_08.jpg', 'bkg_09.jpg', 'bkg_10.jpg', 'bkg_11.jpg', 'bkg_12.jpg', 'bkg_13.jpg', 'bkg_14.jpg', 'bkg_15.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]);

?>[/code]

Suppose you call this PHP file [b]my_bg.php[/b] then you can use this file directly in the CSS (or use htaccess to redirect that file using a JPG call instead).[/quote]


