Indexhibit
Index + Exhibit

Login:

Created by
Daniel Eatock
Jeffery Vaska
And You

Random Background, one solution

 

Indexhibit version: 2.0
Thread is not resolved.

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

Just thought I'd share this customization. Looking around the forums I found bits and pieces but nothing gave me a definitive solution. So this is my "quick and dirty" way to enabled a fullscreen random background image in 2.0. IMPORTANT DISCLAIMER: Please keep in mind this modifies how the backgrounder works across all exhibits, so if you need separate backgrounds on different sections/exhibits you aren't going to want to use this. I use this method to generate a random background on my "Main" section which is hidden– the default "homepage" as it were. I do not have backgrounds on any of my exhibits, just text and image content. If I were to try and upload a background image on those exhibits they would automatically load the random background images.

That being said, I think this can be useful for people who are trying to accomplish the same functionality I am. I know there is probably a better way to do this which doesn't permanently alter the backgrounder plugin, but I'm not a big coder so please feel free to contribute if you have suggestions/improvements.

First put all your background images in a folder in your root directory. I called my "randombg".

  1. Second, make a "random_bg.php" file with the following code:
  2. <?php
  3. $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' 'bg_10.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]);
?>

Save this file in the same directory as your background images. Make sure your filenames match.

Third, modify the "plugin.backgrounder.php" file in your plugins folder. Find line 14 and change this:

  1. $style .= ($OBJ->vars->exhibit['bgimg'] != '') ? "nbackground-image: url(" . $OBJ->baseurl . "/files/" . $OBJ->vars->exhibit['bgimg'] . ");nbackground-repeat: $tiling;nbackground-position: 215px 0;nbackground-attachment: fixed;n" : '';

to this:

  1. $style .= ($OBJ->vars->exhibit['bgimg'] != '') ? "nbackground: url(" . $OBJ->baseurl . "/randombg/random_bg.php"  . ") no-repeat center center fixed;n-moz-background-size: cover;n-webkit-background-size: cover;n-o-background-size: cover;nbackground-size: cover;n" : '';

Save and upload that.

Fourth, edit your exhibit (in my case my hidden "Main" exhibit which functions as my homepage) and upload a background. It doesn't matter what the background is, this is just to activate the plugin.backgrounder.php, the modifications to the code will point to your PHP script which calls a random image from your folder.

Bob's your uncle.

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

Ahh, the forum breaks the code tag when using full line breaks. Sorry about that, code should still be okay though.

I'll try again just so it looks pretty:

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post
  1. <?php
  2. $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' 'bg_10.jpg'
  3. $img_rnd  rand0 sizeof$img_array  1
  4. header'Content-type: image/jpg'
  5. header'Content-Disposition: filename='  $img_array$img_rnd
  6. readfile$img_array$img_rnd
  7. ?>
papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

Damn this parsing, use the code in the first post, the forum removed the periods and parenthesis from the code in the last post which will probably break the php.

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

Just thought of a modification to Indexhibit which might make the whole thing easier.

Instead of only being able to upload a background image maybe we could add a URL for our background?

Then you could use the php scirpt/folder method above and just add the URL to the php file. Elegant!

Maybe something for the next 2.0.x update? ;)

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

Forgot to mention, thanks to arsondpi for his help in this post:
indexhibit.org/forum/thread/16431/
It is what I referenced.

Vaska A
UNITED STATES
2 year(s) ago
Permalink Post

The problem with your suggestion is that it's not intuitive enough for your standard user around here. We have to find a better way than adding a link for this.

I'm nearly finished (I say this too much) with a better background format that will serve as a basis for many other background related things. But, I've been spending too much time helping people lately...I guess I need to disappear for a couple weeks.

;)

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

Fair enough, but hopefully this will be useful for somebody looking to do achieve a similar result.

Looking forward to the new background format when it is finished!

audience
SWEDEN
2 year(s) ago
Permalink Post

I can't get it to work.

It seems that I've done everything correct.
Ive created the .php added it to the bg folder. Changed the backgrounder plugin and changed which folder to point at, and I've added a bg in my main.

What else is there to it? :/

bjornstensson.se

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

audience, I can't see your site. You just have a splash page saying you have a new site coming soon. Kind of makes it hard to troubleshoot. Do you have the Indexhibit site in a subfolder or somewhere I can look at?

Make sure your server allows you to run standalone PHP scripts/call functions. That could be one issue possibly.

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

And make sure not to use the php code in the third post in this thread. The way it was parsed on the forum actually stripped out some characters and I'm pretty sure it breaks the code.

Use the code in the first post.

Post your code so we can see it to double check.

audience
SWEDEN
2 year(s) ago
Permalink Post

Papercrate,

The server is allowing php scripts so the problem must be elsewhere :/

Is it something I need to have in the style.css file for instance? About background in body?

Well, I just started with the site but the background is quite essential for me. But here you have some more.

bjornstensson.se/index.php/portfolio/

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

I'm not sure what the problem is. Let's troubleshoot:

-First things first. What is the folder of your random backgrounds on your server? At least then we can view the PHP file and make sure that is working. Give us the link.
-Is your default or main exhibit your "homepage"? Make sure you have the background uploaded to that main exhibit.
-Show is your code, let's see the changes to you made to the "plugin.backgrounder.php" file.
-It looks like you have a pretty customized layout at the moment, maybe the modifications you've made to get that have compromised the ability to accomplish this?

audience
SWEDEN
2 year(s) ago
Permalink Post

papercrate, I love that you are taking time to help me, thank you.
The php file is in root/bgs/random_bg.php

and this is the code for the random_bg.php

audience
SWEDEN
2 year(s) ago
Permalink Post
  1. <?php
  2. $img_array  array'bg1.jpg' 'bg2.jpg' 'bg3.jpg' 'bg4.jpg' 'bg5.jpg' 'bg6.jpg'
  3. $img_rnd  rand0 sizeof$img_array  1
  4. header'Content-type: image/jpg'
  5. header'Content-Disposition: filename='  $img_array$img_rnd
  6. readfile$img_array$img_rnd
  7. ?>
audience
SWEDEN
2 year(s) ago
Permalink Post

and yes, my main exhibit is my homepage and a background is uploaded there.

  1. <?php if defined'SITE' exit'No direct script access allowed'

function backgrounder()
{
    $OBJ =& get_instance();
    
    if (($OBJ->vars->exhibit['color'] == '') && ($OBJ->vars->exhibit['bgimg'] = '')) return;
    
    $style = (strtolower($OBJ->vars->exhibit['color']) != 'ffffff') ? "background-color: #" . $OBJ->vars->exhibit['color'] . ";" : '';
    
    $tiling = ($OBJ->vars->exhibit['tiling'] != 1) ? 'no-repeat' : 'repeat';
    
    $style .= ($OBJ->vars->exhibit['bgimg'] != '') ? "nbackground: url(" . $OBJ->baseurl . "/bgs/random_bg.php" . ") no-repeat center center fixed;n-moz-background-size: cover;n-webkit-background-size: cover;n-o-background-size: cover;nbackground-size: cover;n" : '';
    
    // nothing to add
    if ($style == '') return;
    
    $OBJ->page->exhibit['dyn_css'][] = "body { $style }";
}

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

Well, something is wrong with the PHP file or your server allowing you to do that. You should get a random background image by visiting:
bjornstensson.se/bgs/…

And we don't get one. Something isn't working there. Make sure you filenames are correct in the array.

The forum doesn't parse our code very nice so I can't tell if you've made a mistake. Follow this link and make sure you code is identical to what is written here:
icyphoenix.com/…

But obviously change the filenames as required to match yours.

Let me know once you've done that and we can see if the PHP script is working.

audience
SWEDEN
2 year(s) ago
Permalink Post

Thank you!

It now works!

Commas, equal signs, backslashes etc etc were missing from both codes.

Thank you papercrate, your the man.

audience
SWEDEN
2 year(s) ago
Permalink Post

Papercrate or someone else? do you know if can I center the random background image? Cuz I have figured it out when I now try to center the slideshow it centers it on the background image.

Bjornstensson.se

papercrate
UNITED KINGDOM
2 year(s) ago
Permalink Post

Do you have that defined in your backgrounder.php file like above? Fixed, center, center?

Always make sure you have the following css defined in the style.css of your theme:

  1. background: no-repeat center center fixed;
  2. background-size: cover;
  3. -webkit-background-size: cover;
  4. -moz-background-size: cover;
  5. -o-background-size: cover;

MRPW
CANADA
2 year(s) ago
Permalink Post

:c

philwilson.ca/randombg/…

I tried to follow the steps exactly - no dice.

philwilson.ca

Plumm
CZECH REPUBLIC
1 year(s) ago
Permalink Post

I tried to make this work whole day and i failed.:( Looks like I have some troubles with the random_bg.php. I copied and pasted the code from this link icyphoenix.com/… but everything I get is this error: plummart.com/randombg/…

papercrate, do you have any ideas, what's wrong? Thank you for your help.

Plumm
CZECH REPUBLIC
1 year(s) ago
Permalink Post

Problem solved. I had one space at the beginning in front of

Plumm
CZECH REPUBLIC
1 year(s) ago
Permalink Post

... in front of ?php
Now it works. Great! Thanks.

danalive
AUSTRALIA
1 year(s) ago
Permalink Post

Hi All,

Trying to make this code work. I have the random_bg.php working fine at:
[a]danko.com.au/randombg/random_bg.php[/…]

I have also added the following code to plugin.backgrounder:
$style .= ($OBJ->vars->exhibit['bgimg'] != '') ? "nbackground: url(" . $OBJ->baseurl . "/randombg/random_bg.php" . ") no-repeat center center fixed;n-moz-background-size: cover;n-webkitbackground-size: cover;n-o-background-size: cover;nbackground-size: cover;n" : '';

Any issues that you can see? :)

Thanks,
Dan.

ameyedavid
BELGIUM
1 year(s) ago
Permalink Post

Bonjour,
J'ai bien fais et suivi a la lettre les explications ci dessus. malheureusement cela ne fonctionne pas; Voici le site que je prépare pour un ami photographe. arno-brignon.fr/…
Bonne journée à vous tous;
David A

Vaska A
UNITED STATES
1 year(s) ago
Permalink Post

This thread has become a mess - it's barely usable. I'm closing it...

Showing 1 - 27 of 28 posts in Forum » Customize » Random Background, one solution
 

This thread has been closed, thank you.