| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| DesignersTalk > Is it possible to generate one random image every 24 hours? |
|
LinkBack | Thread Tools | Search this Thread |
|
|
#1 (permalink) |
|
Needs help
Join Date: Sep 2004
Posts: 26
|
I want to create a website that is just a picture and maybe a line of text underneath, explaining what the pictures are. Is there a script or something that I can use so that every 24 hours, one random image is shown from a directory including ~300 pictures? The text does not have to change, just the image. The image must remain the same for all browsers for a set amount of time (probably 24 hours) and then when the time is up, another random image is shown. The image can be a random one plucked from the 300, or they can go in order. Random is preferred so that repeats can happen before every image has been displayed. (Obviously I'll change the CHMOD settings so that browsers can't view the images in advance. Naughty naughty people.) I've just drawn this in paintshop to show you what I sort of mean: ![]() If I've forgotten to hide something from my browser that you shouldn't be seeing, ignore it. The image in the middle is obviously the one that is randomly generated. If someone can provide me with a way of doing this effectively, I would be most thankful. NB. If what I desire is not possible, can someone please point me towards a nice and easy script that would change the image everytime the page is reloaded. I really don't want to go for this option but if it seems like the best alternative - let me know if there's something else I could do. |
|
|
|
|
|
#2 (permalink) |
|
Senior Member
Join Date: Jan 2005
Posts: 12,340
|
I'd take a look at cron jobs, which are a feature of Unix (and Linux) servers. They allow you to take time-sensitive server actions (such as, backing up your database every 48 hours or something). You might consider setting one up that could take an image from a folder and place it in another folder. That way you always link to the same image, but the image that's in the folder changes every 24 hours. Not sure how you'd do the description. Maybe the same process, but with an include file... |
|
|
|
#3 (permalink) |
|
389 ppm and rising
Join Date: Aug 2005
Location: Järvenpää, Finland
Posts: 5,484
|
I know next to nothing about PostSCript, so forgive me if this sounds ridiculous to those in the know. If you name all your images from "001.jpg" to "300.jpg", would it not be possible to generate a random number between 1 and 300 and feed that result into the image name selector? |
|
|
|
#4 (permalink) |
|
Senior Member
Join Date: Jan 2005
Posts: 12,340
|
Certainly. However, he wants it to change every 24 hours. Not every time a page loads. Showing a random image is child's play. Showing one at specific intervals in time is teenagers' play. What a lousy metaphor. Not sure what PostScript has to do with it... |
|
|
|
#7 (permalink) |
|
Dog Fighter
Join Date: Oct 2006
Location: Glasgow.
Posts: 50
|
Should be fairly straightforward. Take the number of days passed since Jan 1st 2007 (or any other arbitrary date) then mod it by the number of images you have. You could always throw in some other crazy calculations before the mod to totally randomize it. Then name your images 0001.jpg, 0002.jpg etc. |
|
|
|
#8 (permalink) | |
|
Registered User
Join Date: Sep 2006
Location: Leeds
Posts: 97
|
Quote:
Yeah, just do it in php, assign an image to a day of the month.. bobs your uncle. |
|
|
|
|
#9 (permalink) |
|
Senior Member
Join Date: Jan 2005
Posts: 12,340
|
Now that I think of it, you could name the images something like: YYYY-MM-DD.jpg Then something akin to: HTML Code:
Or even just "m-d". The year could be included to make it work across different years. |
|
|
|
#10 (permalink) |
|
geek
|
If you're files are sequentially named (0001.jpg ,0002.jpg...) and you know what the number of the last image is. you can do something like this: PHP Code:
Seeding with date('mdy') will cause rand to spit out the same number until the date changes. this way you don't need to have an image save specifically for that day. or if it's just directory of images you can create and array of all the files in that dir and and use rand to select a key form the array. the problem there is every time the page load the directory will be read so you may want to put the list of file in to a text file or some intermediate step to prevent repeatedly reading the directory |
|
|
|
#12 (permalink) |
|
Needs help
Join Date: Sep 2004
Posts: 26
|
I don't know php at all. Can you please explain what I need to do? :/ edit: http://pr0xay.freehostia.com/image.html ehm.. Last edited by helpmeplz : 10-04-2007 at 18:14. |
|
|
|
#15 (permalink) |
|
Needs help
Join Date: Sep 2004
Posts: 26
|
Thank you inpixel. One problem I seem to have is the image name that it generates. PHP Code:
The problem there is the images are named 001.jpg upto 054.jpg. The only fix I know was to change the last line to PHP Code:
Like I've said the last image at the moment is 054 as I've not done enough pictures to last a whole year. With gk's code, what'll happen in 55 days time? I really don't understand how it works, or why it's given me number one first, so hopefully you can shed some light on this. Thanks a lot for the help so far. |
|
|
|
#16 (permalink) |
|
hmmm...
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,127
|
printf is your friend Code:
PHP: sprintf - Manual |
|
|
|
#17 (permalink) |
|
Needs help
Join Date: Sep 2004
Posts: 26
|
I feel so thick! I changed it to: PHP Code:
But on the page source it comes out as PHP Code:
And the pic doesn't display. |
|
|
|
#20 (permalink) |
|
Needs help
Join Date: Sep 2004
Posts: 26
|
Hmm, I think it has worked. This is the code I used: PHP Code:
And this is the page: website For me, it shows the picture 001.JPG. Is that supposed to be shown? Will it be different tomorrow? If so, I better get more than fifty four images done A-Sap! Thanks for the help (so far) everyone. Much appreciated. Last edited by helpmeplz : 05-05-2007 at 14:09. |
|
![]() |