4images Forum & Community

4images Modifications / Modifikationen => Templates & Styles (Releases & Support) => Topic started by: x23piracy on November 16, 2010, 09:49:51 AM

Title: [Style] Fullscreen Random Background Image
Post by: x23piracy on November 16, 2010, 09:49:51 AM
Hi,

this changes randomly (page reload) the background image in your galery.
For me it's used for the hole galery but it can be easily adapted to work
for different categories or template html files...

Before we begin some examples (press strg while clicking on image):

(http://www.4homepages.de/forum/index.php?action=dlattach;topic=28280.0;attach=5959;image) (http://www.4homepages.de/forum/index.php?action=dlattach;topic=28280.0;attach=5958;image) (http://www.4homepages.de/forum/index.php?action=dlattach;topic=28280.0;attach=5961;image]) (http://www.4homepages.de/forum/index.php?action=dlattach;topic=28280.0;attach=5960;image) (http://www.4homepages.de/forum/index.php?action=dlattach;topic=28280.0;attach=5963;image]) (http://www.4homepages.de/forum/index.php?action=dlattach;topic=28280.0;attach=5962;image)


Here we go:

Step 1

Add this to your style.css:

Code: [Select]
img.bg {
/* Set rules to fill background */
min-height: 100%;
min-width: 1024px;

/* Set up proportionate scaling */
width: 100%;
height: auto;

/* Set up positioning */
position: fixed;
top: 0;
left: 0;
}

@media screen and (max-width: 1024px){
img.bg {
left: 50%;
margin-left: -512px; }
}



Step 1.2

This step is important, else you will just see the background image

In your style.css locate you main container (normally "container") and set:

Code: [Select]
position: relative;


Step 2

Create a file called "randombg.php" and paste:

Code: [Select]
<?php
#FILE: random_image.php - Version 1.3
#
#INSTALLATION INSTRUCTIONS:
# 1) Save this php code to your server.
# 2) Make sure the script has execute permissions.
# 3) Make sure your $IMAGE_DIRECTORY has read permissions, as well
# as the files within that directory.
# 4) Change:
# $IMAGE_DIRECTORY = "../pictures/";
# as described in the php code below.
# 5) Make your IMG tag look similar to the following:
# <IMG SRC="/scripts/random_image.php" ALT="">
#
#ABOUT THIS SCRIPT:
#       This is a very simple php script. All it does is grab a 
#random image from a directory and print it out, hiding the actual
#filename of the image displayed. Currently, this
#script just works with gif and jpg/jpeg images. 
#
#HISTORY:
# ??/??/?? 1.3 Updated and streamlined the code with
# release of java version
# ??/??/?? 1.2 Updated with ASP release
# ??/??/?? 1.1 Original release
#
#AUTHOR:
# http://www.davelozinski.com/scripts
#
#BEGIN CONFIGURATION ITEMS:
#The full path listing to the directory which contains the images
#to be randomly chosen and displayed. 
#Unix users should be able to get away with specifying a relative path.
#NT users may have to specify the full system path, which will probably
#need to look similar to: 
#"c:\\wwwroot\\htdocs\\images\\" or
#"f:/Inetpub/wwwroot/images/"
$IMAGE_DIRECTORY "";

###Nothing below this line should need to be configured.###
$line "";
$randomNumber0;
$imageFiles = array();
$fileName "";
$x=0;
if (
$DIR opendir($IMAGE_DIRECTORY)) {
while ($fileName readdir($DIR)) {
if (is_dir($IMAGE_DIRECTORY $fileName)) { continue; }
if (!preg_match("/\w/"$fileName)) { continue; }
if (preg_match("/\.gif$|\.jpg$|\.jpeg$/i",$fileName)) {
$imageFiles[$x] = $fileName;
$x+=1;
}
}
closedir($DIR);
srand((double)microtime()*1000000);
$randomNumber rand(0,(count($imageFiles) - 1));
Header ("Pragma: no-cache\n");
if (preg_match("/\.gif$/i",$imageFiles[$randomNumber])) {
Header ("Content-type: image/gif\n\n");
} elseif (preg_match("/\.jpg$|\.jpeg$/i",$imageFiles[$randomNumber])) {
Header ("Content-type: image/jpg\n\n");
} else { #Not a gif or jpeg file. Exit the program.
exit;
}
$fp fopen ($IMAGE_DIRECTORY $imageFiles[$randomNumber], "rb");
echo (fread($fp,filesize($IMAGE_DIRECTORY $imageFiles[$randomNumber])));
fclose($fp);
}
exit;
# random_image.php
?>



Step 2.1

in randombg.pgp set the path to your background images:

Code: [Select]
$IMAGE_DIRECTORY = "";


Step 3

Place this in every template file where you want to display the background image:

Code: [Select]
<img border="0" src="randombg.php" class="bg">

All done



Tips

You can also point $IMAGE_DIRECTORY = ""; to your data directory for use with
background images out of the category where you within.


Greetz X23
Title: Re: [Style] Fullscreen Random Background Image
Post by: Jan-Lukas on November 16, 2010, 08:05:00 PM
Hast Du keinen Platz für die Bilder, wo keine Werbung das Bild versperrt ?
Title: Re: [Style] Fullscreen Random Background Image
Post by: x23piracy on November 16, 2010, 08:30:49 PM
Hast Du keinen Platz für die Bilder, wo keine Werbung das Bild versperrt ?

fixed...

Der Ü-Ei Mann :) Ich hab noch ne Schlumpfine mit Springseil... (80er)


Gruß Jens
Title: Re: [Style] Fullscreen Random Background Image
Post by: Sunny C. on November 16, 2010, 11:22:41 PM
Sehr nett, aber das werde ich nicht einsetzen können, weil das einfach ganz schön viel laderrei für die Seite ist!
Auf kleinen Seiten ist das sicherlich was ganz tolles.

Wenn du ein weitere schreiben würdest, womit man den Hintergrund durch "Hintergrundfarbe" ändern kann, wäre das super :D

Wenn du Hilfe brauchst, schreib mir!
Title: Re: [Style] Fullscreen Random Background Image
Post by: x23piracy on November 16, 2010, 11:30:30 PM
Sehr nett, aber das werde ich nicht einsetzen können, weil das einfach ganz schön viel laderrei für die Seite ist!
Auf kleinen Seiten ist das sicherlich was ganz tolles.

Wenn du ein weitere schreiben würdest, womit man den Hintergrund durch "Hintergrundfarbe" ändern kann, wäre das super :D

Wenn du Hilfe brauchst, schreib mir!

Hi,

laderei ich bitte dich das ist ne Bildergalerie da wird ständig was geladen ;)
(Ich nehme an du redest von Seiten mit richtig viel "Verkehr")

Hintergrundfarbe? Du meinst anstatt einem Bild einfach eine wechselnde Farbe
oder die möglichkeit auf klick zu wechseln?

Ich frag dich erst wenn mir google nicht hilft ;)  :thumbup:


Gruß Jens
Title: Re: [Style] Fullscreen Random Background Image
Post by: al3aredh on February 04, 2015, 07:11:23 PM
thanks