The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Background Randomizer?

4 posters

Go down

Solved Background Randomizer?

Post by CloverTea August 11th 2010, 5:28 am

Is there a way to make it so a different background image displays every time the page is loaded?

Any help or suggestions are appreciated! Thanks~

-Clover
CloverTea
CloverTea
Forumember

Female Posts : 99
Reputation : 0
Language : English

http://clover.top-forum.net

Back to top Go down

Solved Re: Background Randomizer?

Post by blindbat1457 August 11th 2010, 6:08 am

I am sure there is just have to find the script for it.. Not sure where that script goes.
blindbat1457
blindbat1457
Forumember

Male Posts : 667
Reputation : 6
Language : English
Location : Santa Clarita, CA

Back to top Go down

Solved Re: Background Randomizer?

Post by HwyStar August 13th 2010, 3:21 pm

See my Forum: Reno Bike Forum

This is advanced stuff but here goes anyway:

Create a php script file like this one on a PHP server you have access to in a folder like D:\WWW\MyWebSite\images\randompic.php:
Code:

<?php

  function initRand ()
  {
    static $randCalled = false;
    if (!$randCalled)
    {
      srand((double) microtime() * 1000003);
      $randCalled = true;
    }
  }
  function randNum ($low, $high)
  {
    initRand();
    $rNum = rand($low, $high);
    return $rNum;
  }

  $extList = array();
  $extList['jpg']  = 'images/jpeg';

  $imageNumber = randNum(1, 30);
  $img = './pic'.$imageNumber.'.jpg';

  if ($img!=null)
  {
    $imageInfo = pathinfo($img);
    $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
    header ($contentType);
    readfile($img);
  }
  else
  {
    if ( function_exists('imagecreate') )
    {
        header ("Content-type: image/png");
        $im = @imagecreate (100, 100) or die ("Cannot initialize new GD image stream");
        $background_color = imagecolorallocate ($im, 255, 255, 255);
        $text_color = imagecolorallocate ($im, 0,0,0);
        imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
        imagepng ($im);
        imagedestroy($im);
    }
  }
?>
I know there is tighter, better ways to code this in PHP but this works just fine for me.

After you have created the above file on a PHP server, then in the ACP, Display, Pics Management you will add a pointer to the PHP file you created like: http://myphpserver.com/MyWebSite/images/randompic.php

Your forum will run the php code! When you create your images under the image directory, name them like: pic1.jpg, pic2.jpg. You will see in the PHP code that it calls random pictures in this format. If you have trouble doing this get one of your programmer friends to help you clean up the problem. There are many ways that this won't work for you so don't be surprised! Like I said this is advanced stuff...
HwyStar
HwyStar
New Member

Male Posts : 18
Reputation : 0
Language : English
Location : Virginia

http://www.RenoBikeClub.com

Back to top Go down

Solved Re: Background Randomizer?

Post by Guest August 13th 2010, 4:23 pm

@HwyStar, Forumotion doesn't support php Smile
avatar
Guest
Guest


Back to top Go down

Solved Re: Background Randomizer?

Post by HwyStar August 13th 2010, 4:46 pm

Look at my forum Gangstar15... My forum link is in my post. I have used this same code on other Forumotion forums with little problems. If I am in violation of any of the forum rules then please let me know and I will retract my post.
HwyStar
HwyStar
New Member

Male Posts : 18
Reputation : 0
Language : English
Location : Virginia

http://www.RenoBikeClub.com

Back to top Go down

Solved Re: Background Randomizer?

Post by Guest August 13th 2010, 4:50 pm

Hmm, sorry my bad then, i though it wasen't forumotion forum Smile
avatar
Guest
Guest


Back to top Go down

Solved Re: Background Randomizer?

Post by HwyStar August 13th 2010, 4:59 pm

Your good man! PHP can be used in the pointers to pictures in many different ways, i.e.: Banner, Categories, etc. It can make for some really fun effects changing things up. Use a different category color by day, etc.

I have created shout boxes using php and pointed to our php server using an html page, or even in the message code of the forum. There are all kinds of tweaks you can do in the background if you have access to your own php server and the knowledge to pull it off. Sometimes it can get a little confusing.

My forum is Forumotion through and through. The service they provide rocks!
HwyStar
HwyStar
New Member

Male Posts : 18
Reputation : 0
Language : English
Location : Virginia

http://www.RenoBikeClub.com

Back to top Go down

Solved Re: Background Randomizer?

Post by Guest August 13th 2010, 5:03 pm

I know php, i mean i know how cool its, i used it for making homepages for online games private server, Smile.

but back to topic ^^
avatar
Guest
Guest


Back to top Go down

Solved Re: Background Randomizer?

Post by CloverTea August 14th 2010, 4:06 am

Thanks hwystar! I saw the example on your forum and it looks really nice.

I'll try this and get back to you if I have questions.
CloverTea
CloverTea
Forumember

Female Posts : 99
Reputation : 0
Language : English

http://clover.top-forum.net

Back to top Go down

Solved Re: Background Randomizer?

Post by HwyStar August 14th 2010, 5:09 pm

Send me a PM if you need any help! It can get tricky if you don't have any programming experience.
HwyStar
HwyStar
New Member

Male Posts : 18
Reputation : 0
Language : English
Location : Virginia

http://www.RenoBikeClub.com

Back to top Go down

Solved Re: Background Randomizer?

Post by CloverTea October 3rd 2010, 9:28 pm

@HWY: So I made the file, it's

sweetcharm.net/randomimage.php

Now..where exactly do I put that URL?


also, where do I put the image urls?.....
CloverTea
CloverTea
Forumember

Female Posts : 99
Reputation : 0
Language : English

http://clover.top-forum.net

Back to top Go down

Solved Re: Background Randomizer?

Post by MDragon October 4th 2010, 12:50 am

Hey HwyStar, this is awesome. You should make a tutorial about this.

By the way, I want to do the same thing to my logo on my forums. Can you show me the code for such (or preferably, PM it?)? That would be amazing.

By the way, when you say add a pointer PHP file in Pics Management, how exactly do I do that? And do I host the images in the same place that I have the PHP file?

I don't know if I should ask this in this topic itself, but thanks CloverTea for asking the question in the first place
MDragon
MDragon
New Member

Posts : 9
Reputation : 0
Language : English

http://sekieiplateau.4rumer.com/portal.htm

Back to top Go down

Solved Re: Background Randomizer?

Post by HwyStar October 4th 2010, 3:29 pm

The link to your php code goes in the Forum Main Logo field under:
Pictures and Colors, Pics Management, Advanced Mode window of the ACP.

Make sure you specify the http:// as in: http://sweetcharm.net/randomimage.php

The path to your graphic files should reside in the images directory of sweetcharm.net since my php code is referencing that directory. You could modify this line of code to change the images directory to your directory, if you want:
$extList['jpg'] = 'images/jpeg';

Each file I have in the images directory is named: pic1.jpg, pic2.jpg, etc. This way the php code will randomize between 1 and 30. Modify the php code to have the number of files you have created. Modify this line of code to be your number of files:
$imageNumber = randNum(1, 30);

Dragon: I really don't have time to create a tutorial since I run a business and it takes all my time... Once you master this concept Dragon then please pass it forward! Smile Use the code I provided up above in the code segment. CloverTea is close to perfecting the concept as well so she may be able to help you. PM me and I will be happy to help!
HwyStar
HwyStar
New Member

Male Posts : 18
Reputation : 0
Language : English
Location : Virginia

http://www.RenoBikeClub.com

Back to top Go down

Solved Re: Background Randomizer?

Post by CloverTea October 16th 2010, 10:26 pm

Oh my gosh I got this to work!!!!!!!!!!!!!!! THANK YOU SO MUCH HWYSTAR FOR ALL YOUR HELP <333 The script looks and works great! I can try to answer questions as people have them as well now.
CloverTea
CloverTea
Forumember

Female Posts : 99
Reputation : 0
Language : English

http://clover.top-forum.net

Back to top Go down

Solved Re: Background Randomizer?

Post by Guest October 16th 2010, 10:28 pm

Background Randomizer? Stock_lock-ok Solved Background Randomizer? 103 Locked
avatar
Guest
Guest


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum