[Script]Random (header) image

Discussion forum for MOD Writers regarding MOD Development.
Locked
remek
Registered User
Posts: 4
Joined: Sat Mar 21, 2009 3:41 pm

[Script]Random (header) image

Post by remek »

This is my first post here so hi to all.

I've just made a simple script I want to share. It displays random image, and on special occasion it displays images from another directory. Example use may be forum's header.

Download it here or here.

Usage.
Put images to 'SCRIPT_DIR/images'.

If you want to display different images on e.g. Valentine's Day (blahhh) create directory 'SCRIPT_DIR/images/14-02' and put there images.

It is also possible to display different set of images within dates, e.g 'SCRIPT_DIR/images/24-12-26-12' will display Xmas images from 24-Dec to 26-Dec and then will display images from 'SCRIPT_DIR/images' back.

Filenames are not important except extension must be '.jpg' - the script reads all files in directory.

Then, all you need to do is to call script instead of image file e.g.
in HTML replace

Code: Select all

<img src="http://someserver.com/styles/images/header.jpg">
with

Code: Select all

<img src="http://someserver.com/SCRIPT_DIR/random_image.php">
or in CSS
replace

Code: Select all

.someclass {background-image: url(http://someserver.com/styles/images/header.jpg)}
with

Code: Select all

.someclass {background-image: url(http://someserver.com/SCRIPT_DIR/random_image.php)}
Here is how it works: http://forum-subaru.pl (board is in polish, but you'll get the idea ;-) )

p.s. I know it isn't masterpiece of coding but it works as expected :mrgreen:
Last edited by ckwalsh on Sun Mar 22, 2009 4:17 am, edited 1 time in total.
Reason: Moved to MOD Writer's Discussion

denisdale
Registered User
Posts: 2
Joined: Sun Mar 22, 2009 4:19 am

Re: [Script]Random (header) image

Post by denisdale »

This is all new to me so I have a few basic questions to ask.

Do I create a folder called "images" under my "styles/name_of_style" folder? If not where do create it?
I then put all the jpg images I have created for the header into this folder?
Where do I save the random_image.php script?
What is the location and name of the file I need to change to direct the calls to random_image.php?
thanks,
:?:

remek
Registered User
Posts: 4
Joined: Sat Mar 21, 2009 3:41 pm

Re: [Script]Random (header) image

Post by remek »

denisdale wrote:This is all new to me so I have a few basic questions to ask.

Do I create a folder called "images" under my "styles/name_of_style" folder? If not where do create it?
I then put all the jpg images I have created for the header into this folder?
Where do I save the random_image.php script?
:?:
Denisdale,
Create a directory on your web server, for example 'header'. Copy randon_image.php there.
Then create directory 'images' in 'header'. Put there jpgs.

If you want different sets of images on selected dates, create new directory under images directory naming it with the following scheme:
daystart-monthstart (for 21th march it will be '21-03')
or
daystart-monthstart-dayend-monthend (for 8th april till 21st april it will be '08-04-21-04').

This is standalone script, so it does not matter if you put the files somewhere in phpBB installation path. It may be even different server.

Instead of calling directly jpg file in tag or css, you call the script. According to directories above you call it with url 'http://yourserver.com/header/random_image.php'.

denisdale
Registered User
Posts: 2
Joined: Sun Mar 22, 2009 4:19 am

Re: [Script]Random (header) image

Post by denisdale »

I have created the "header" folder, copied the php file and put some jpgs in the "images" sub folder.

I am not sure what to do with your last instruction:
Instead of calling directly jpg file in tag or css, you call the script. According to directories above you call it with url 'http://yourserver.com/header/random_image.php'.

Where do I put this? :?:

User avatar
bonelifer
Community Team Member
Community Team Member
Posts: 3482
Joined: Wed Oct 27, 2004 11:35 pm
Name: William
Contact:

Re: [Script]Random (header) image

Post by bonelifer »

This is how I did my header. It was suggested by someone on the Styles Team to make it fixed width so that the header didn't repeat multiple times. I've included that in my instructions. This should be simpler than what remek has done on his site and should suffice for the majority of people.

Open styles/prosilver/theme/common.css, find:

Code: Select all

#wrap {
   padding: 0 20px;
   min-width: 650px;
}
and change it to(these are the numbers I came up with to approximate the fixed width of phpbb.com):

Code: Select all

#wrap {
   padding: 0 20px;
   min-width: 650px;
   min-height: 127px;
   width: 848px;
   margin: 0 auto;
}
Open styles/prosilver/theme/colours.css, find:

Code: Select all

.headerbar {
	background-color: #12A3EB;
	background-image: url("{T_THEME_PATH}/images/bg_header.gif");
	color: #FFFFFF;
}
replace with(Remember to change the URL below), should be noted that I used the images folder in the root of the forum(this wasn't a typo):

Code: Select all

.headerbar {
	background-color: #12A3EB;
	background-image: url("http://www.YOURWEBSITENAME.net/YOURFORUMFOLDER/images/header/random_image.php");
	color: #FFFFFF;
}
It should also be noted that my images were 850x137. You should have all your images the same width and height. You'll notice the common.css edit has "width: 848px;" which is two pixels smaller than the width of the image, this important. That number should always be 2 pixels small than the images real width. The " min-height: 127px;" should always be 10 pixels smaller than your images actual height.
Knowledge Base | phpBB Board Rules | Search Customisation Database
Image
Please don't contact me via PM or email for phpBB support .

remek
Registered User
Posts: 4
Joined: Sat Mar 21, 2009 3:41 pm

Re: [Script]Random (header) image

Post by remek »

Little explanation to bonelifer.
bonelifer wrote: It should also be noted that my images were 850x137. ...
I have different approach because my site is not fixed width, and I sometimes wanted header image to be 640 and sometimes 700 or whatever - with gradient on left side ;-) Sometimes I changed the 'background' colour etc. ...and search input was on right side of header - over image (now it is not ;-) ) - heres different version of the same script/template

User avatar
bonelifer
Community Team Member
Community Team Member
Posts: 3482
Joined: Wed Oct 27, 2004 11:35 pm
Name: William
Contact:

Re: [Script]Random (header) image

Post by bonelifer »

remek I noticed that, while delving into your sites source. :D That's what I meant by my way being easier. Thanks for the script, when I update my forum this week, I'm going to be using your script instead of the old one I was using.
Knowledge Base | phpBB Board Rules | Search Customisation Database
Image
Please don't contact me via PM or email for phpBB support .

remek
Registered User
Posts: 4
Joined: Sat Mar 21, 2009 3:41 pm

Re: [Script]Random (header) image

Post by remek »

bonelifer wrote:Thanks for the script, when I update my forum this week, I'm going to be using your script instead of the old one I was using.
Cool. I'm really glad someone may find the script useful. :D

lsuedulive
Registered User
Posts: 10
Joined: Wed Mar 18, 2009 7:08 am

Re: [Script]Random (header) image

Post by lsuedulive »

remek wrote:I have different approach because my site is not fixed width
remek,

I am very new and this is hard for me to understand.

For your code to work on my site what do I do first? Delete the logo.png and delete the header info ?

This is the new site: http://melvillehighschool.us

lsuedulive
Registered User
Posts: 10
Joined: Wed Mar 18, 2009 7:08 am

Re: [Script]Random (header) image

Post by lsuedulive »

bonelifer wrote:This is how I did my header. Open styles/prosilver/theme/common.css
bonelifer,

I am new can you advise on the ways I can open the CSS on my site? I am using FTP to bring the file here then edit and FTP back. Is that bad ?

Thank you

User avatar
bonelifer
Community Team Member
Community Team Member
Posts: 3482
Joined: Wed Oct 27, 2004 11:35 pm
Name: William
Contact:

Re: [Script]Random (header) image

Post by bonelifer »

lsuedulive wrote:
bonelifer wrote:This is how I did my header. Open styles/prosilver/theme/common.css
bonelifer,

I am new can you advise on the ways I can open the CSS on my site? I am using FTP to bring the file here then edit and FTP back. Is that bad ?

Thank you

It's not inherently bad. I personally use Notepad++(A Notepad replacement) with it's FTP plugin. Once you enter the FTP login information it as simple as logging in and going to the correct directory and clicking on the correct file. Only thing I suggest when using it is to save each file one at a time instead of using the SAVE-ALL button. It's great as you can edit all the files, then save them when you are done editing.

The download is http://notepad-plus.sourceforge.net/uk/site.htm

You might want to check out there 3rd party plugins as well.
Knowledge Base | phpBB Board Rules | Search Customisation Database
Image
Please don't contact me via PM or email for phpBB support .

lsuedulive
Registered User
Posts: 10
Joined: Wed Mar 18, 2009 7:08 am

Re: [Script]Random (header) image

Post by lsuedulive »

bonelifer wrote:It's great as you can edit all the files, then save them when you are done editing.

The download is http://notepad-plus.sourceforge.net/uk/site.htm

You might want to check out there 3rd party plugins as well.
bonelifer,

I have a new high school site with nothing in it yet. How much will you charge me to make it work in the header? LSUEDU@LIVE.COM

http://melvillehighschool.us

User avatar
irdem
Registered User
Posts: 172
Joined: Sat Oct 13, 2007 10:31 pm
Contact:

Re: [Script]Random (header) image

Post by irdem »

hello,
i installed this script. but have errors on lines 14 and 16 in my log file for random.php.
there is ;; at the end of ligne 14.
but i don't know what is the problem on line 16

youngjediknight
Registered User
Posts: 385
Joined: Wed Apr 22, 2009 2:58 pm

Re: [Script]Random (header) image

Post by youngjediknight »

Don't mean to revive an old thread but need a randomizer like this one for the header image. I prefer one that will use any image file in a particular folder rather than one where I have to designate the number of images or or image filenames - much more cumbersome.

I'm trying to incorporate this:

Code: Select all

 <?php
/*
How to use:
1. Place suitable images in the same folder as the script resides.
The images should have a .jpg, .gif or a .png ending.

2. Copy the source of this script in a textfile, rename it avatar.php
(or any other name, as you please) and save it in the same directory as the images.

3. Call the script by appending a random name with the filetype ending.
Example:
http://www.fungifun.org/rotate/avatar.php/example.jpg

avatar.php is the name of the script

example.jpg is a random name, you could also use asasd.jpg or qwfpoa.jpg, the name doesn't matter,
what is important is the ending. The ending determines which files from the folder are used.
So, if you use example.gif, then the gif files in this folder will be used.
*/

$filetype = end(explode(".",$_SERVER['REQUEST_URI']));
if($filetype != "jpg" && $filetype != "gif" && $filetype != "png") exit;
if ($handle = opendir('.')) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && stristr($file, ".".$filetype)) $files[]=$file;
   }
   closedir($handle);
}
if ($files) {
    $imagenr = rand(0, sizeof($files)-1);
    if($filetype == "jpg") $filetype = "jpeg";
    $fp = fopen($files[$imagenr], 'rb');
    header("Content-Type: image/$filetype");
    header("Content-Length: " . filesize($files[$imagenr]));
    fpassthru($fp);
    exit;
}
?> 
In colours.css:

Code: Select all

.headerbar {
	background: url("{T_THEME_PATH}/images/banner/rotate.php/xyz.jpg") no-repeat left top #ffffff;
	color: #FFFFFF;
}
I get a blank background image in the header. When I right-click to view or go directly to it, I get a "image cannot be displayed because it contains errors" message.

If there is an alternate approach, I'm all for it. Just want to get a random image background in the header picking images from a designated folder.

Locked

Return to “[3.0.x] MOD Writers Discussion”