|
|
| Author |
Message |
emm Power User

Joined: 13 Jul 2004 Posts: 310
|
Post subject: Need script for random image |
|
|
Anyone know of a good script to generate and show random image? I don't care if it is server side or client side. What is more efficient? Any tutorial, article, code or link will be good.
Thanks in advance. _________________ “You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh |
|
Mon Aug 30, 04 11:17 pm
 |
|
 |
hasnut Expert User


Joined: 28 Aug 2004 Posts: 201
|
Post subject: |
|
|
Do you want randomly change images on a single page without refresh then you need to use javascript
you can get it by going
http://javascriptkit.com/script/script2/randomslide.shtml
But if you need random image to show up each time someone visites then you can place the links of the images in array and use rendom function to do the randomization.
OR you want your php code to create/generate Images, then you need to use GD library of php. _________________ Sarder Hasnut
MCSD, CIW A
Need Low Cost Prefessional Hosting Contact me |
|
Tue Aug 31, 04 4:29 am
 |
|
 |
emm Power User

Joined: 13 Jul 2004 Posts: 310
|
Post subject: Showing random image everytime someone visits a page |
|
|
Good point about the page having to refresh if I want a server side code. I think, I wanted the javascript solution after all. I do not want a slideshow. How do I make it so that a different image is shown randomly each time a visitor refreshes the page or a new visitor comes? How can I place the links of the images in an array and use the random function? Can you help me please?
I don't want anything that complex as GD library and php! _________________ “You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh |
|
Wed Sep 01, 04 3:07 am
 |
|
 |
hasnut Expert User


Joined: 28 Aug 2004 Posts: 201
|
Post subject: |
|
|
ok steps are
1. put the list of iamges path in a array
2. ramdomize the array with the size of array so you got the index of random array
3. show the indexed path value of imge to browser
hope that helps.
If you want to see code example then let me know which server side language you are using? _________________ Sarder Hasnut
MCSD, CIW A
Need Low Cost Prefessional Hosting Contact me |
|
Wed Sep 01, 04 4:14 am
 |
|
 |
emm Power User

Joined: 13 Jul 2004 Posts: 310
|
Post subject: |
|
|
Yes please some code example will be helpful. Php will be okay, if you can.
Thanks you for all the help. _________________ “You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh |
|
Wed Sep 01, 04 4:19 am
 |
|
 |
hasnut Expert User


Joined: 28 Aug 2004 Posts: 201
|
|
Wed Sep 01, 04 9:39 am
 |
|
 |
emm Power User

Joined: 13 Jul 2004 Posts: 310
|
Post subject: Php random image script |
|
|
I don't know how to thank you. I have not tested it yet. Let me try it and I will come back to you if there is any problem. It should work okay as it look. You are greattttt! _________________ “You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh |
|
Thu Sep 02, 04 2:51 am
 |
|
 |
hasnut Expert User


Joined: 28 Aug 2004 Posts: 201
|
Post subject: |
|
|
I have tested it, it works for me. But if you have any problem running it let me know with the error code you get. Hope my reply will help to solve faster this post to your solution _________________ Sarder Hasnut
MCSD, CIW A
Need Low Cost Prefessional Hosting Contact me |
|
Thu Sep 02, 04 8:07 am
 |
|
 |
emm Power User

Joined: 13 Jul 2004 Posts: 310
|
Post subject: Image rotation php script problem |
|
|
Hi Hasnut,
Problem. The images do not show up. There is no error code. Only four crosses, that means that images cannot be found.  I did everything as you said. I don't know where did I go wrong. What could be the problem? Please.... _________________ “You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh |
|
Fri Sep 03, 04 7:38 am
 |
|
 |
hasnut Expert User


Joined: 28 Aug 2004 Posts: 201
|
Post subject: |
|
|
ok then your path problem
now place all the images to the same folder where the php file is and change the php code to below text (I just changing the path)
| Code: |
<?php
$folder=opendir(".");
while ($file = readdir($folder))
$names[count($names)] = $file;
closedir($folder);
sort($names);
$tempvar=0;
for ($i=0;$names[$i];$i++){
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){
$names1[$tempvar]=$names[$i];$tempvar++;
}
}
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
$hasnut=$names1[$rand_keys[0]];
$dimensions = GetImageSize($hasnut);
if (isset($pic)){header ("Location: $hasnut");}
else {echo "<img src=\"$hasnut\" $dimensions[3]>";}
?> |
_________________ Sarder Hasnut
MCSD, CIW A
Need Low Cost Prefessional Hosting Contact me |
|
Fri Sep 03, 04 12:36 pm
 |
|
 |
emm Power User

Joined: 13 Jul 2004 Posts: 310
|
Post subject: Problem with random php image script |
|
|
Dear Hasnut,
I have tried the code many times and tried to change code around and things. But it's not working for me. I am trying on an apache server that is installed on a windows machine. Can that be a problem?
Few things I also don't understand. Can you please explain. How does a .HTM file use rotateimage.php?pic=random1. I mean html file is not going through the php engine right? Should not the folder name be like "./images" I tried changing that but does not work. Another one is you used random1, random2 etc. after ? in html file. But there is no variable name random in the php file. How does that work.
I am sorry I am causing you so much trouble.  _________________ “You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh |
|
Sun Sep 05, 04 5:49 am
 |
|
 |
hasnut Expert User


Joined: 28 Aug 2004 Posts: 201
|
|
Sun Sep 05, 04 6:04 am
 |
|
 |
emm Power User

Joined: 13 Jul 2004 Posts: 310
|
Post subject: |
|
|
sorry my friend.  _________________ “You might say reality is the result of complex negotiations between the observer and the observed. But that is simply a point of view…”
Digital Bangladesh |
|
Sun Sep 05, 04 6:16 am
 |
|
 |
hasnut Expert User


Joined: 28 Aug 2004 Posts: 201
|
Post subject: |
|
|
This is Bad forum configuration. This making cause the problem and both of us loosing time for that problem
Not me nor you are wrong, problem with the forum form makes the php code changes so you allways got bad code.
to get the orginal php code click post reply, and copy the code from
Topic Review box.
And here is the live show http://www.totalitsolution.com/random/_________________ Sarder Hasnut
MCSD, CIW A
Need Low Cost Prefessional Hosting Contact me |
|
Sun Sep 05, 04 10:04 am
 |
|
 |
hasnut Expert User


Joined: 28 Aug 2004 Posts: 201
|
|
Sun Sep 05, 04 10:21 am
 |
|
 |
|