Home

Forums

Web development

 

 

 

 
     
 
dna88 Web development and Technology Forum
 
Profile   Register   Memberlist   Usergroups   FAQ   Search  Log in
Need script for random image
Goto page 1, 2  Next
 
Post new topic   Reply to topic    dna88 Forum Index -> Web scripting language Discussion Forum
Author Message
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: Need script for random image Reply with quote

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
Back to top
emm View user's profile Send private message
hasnut
Expert User
Expert User


Joined: 28 Aug 2004
Posts: 201

Post Post subject: Reply with quote

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
Back to top
hasnut View user's profile Send private message Visit poster's website MSN Messenger
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: Showing random image everytime someone visits a page Reply with quote

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
Back to top
emm View user's profile Send private message
hasnut
Expert User
Expert User


Joined: 28 Aug 2004
Posts: 201

Post Post subject: Reply with quote

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
Back to top
hasnut View user's profile Send private message Visit poster's website MSN Messenger
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: Reply with quote

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
Back to top
emm View user's profile Send private message
hasnut
Expert User
Expert User


Joined: 28 Aug 2004
Posts: 201

Post Post subject: Reply with quote

create a php file named rotateimage.php with the below code

Code:
<?php
   $folder=opendir("images");
   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]>";}
?>


create a folder "images" in the folder where you place the php file. and place your images in the folder

now create a html file say name index.html with the below script
Code:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<title> Ramndom Image</title>
</head>

<body bgcolor="#ffffff" text="#000000">
<img src="rotateimage.php?pic=random1" border=0 alt=""><br>
<img src="rotateimage.php?pic=random2" border=0 alt=""><br>
<img src="rotateimage.php?pic=random3" border=0 alt=""><br>
<img src="rotateimage.php?pic=random4" border=0 alt=""><br>
</body>
</html>


and test it, hope that helps and it will show 4 random image. if one then call it one time in the html
_________________
Sarder Hasnut
MCSD, CIW A

Need Low Cost Prefessional Hosting Contact me
Wed Sep 01, 04 9:39 am
Back to top
hasnut View user's profile Send private message Visit poster's website MSN Messenger
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: Php random image script Reply with quote

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
Back to top
emm View user's profile Send private message
hasnut
Expert User
Expert User


Joined: 28 Aug 2004
Posts: 201

Post Post subject: Reply with quote

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
Back to top
hasnut View user's profile Send private message Visit poster's website MSN Messenger
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: Image rotation php script problem Reply with quote

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
Back to top
emm View user's profile Send private message
hasnut
Expert User
Expert User


Joined: 28 Aug 2004
Posts: 201

Post Post subject: Reply with quote

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
Back to top
hasnut View user's profile Send private message Visit poster's website MSN Messenger
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: Problem with random php image script Reply with quote

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
Back to top
emm View user's profile Send private message
hasnut
Expert User
Expert User


Joined: 28 Aug 2004
Posts: 201

Post Post subject: Reply with quote

I will upload it to my server and let you see it live tonight. Hope it will help you.
_________________
Sarder Hasnut
MCSD, CIW A

Need Low Cost Prefessional Hosting Contact me
Sun Sep 05, 04 6:04 am
Back to top
hasnut View user's profile Send private message Visit poster's website MSN Messenger
emm
Power User
Power User


Joined: 13 Jul 2004
Posts: 310

Post Post subject: Reply with quote

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
Back to top
emm View user's profile Send private message
hasnut
Expert User
Expert User


Joined: 28 Aug 2004
Posts: 201

Post Post subject: Reply with quote

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
Back to top
hasnut View user's profile Send private message Visit poster's website MSN Messenger
hasnut
Expert User
Expert User


Joined: 28 Aug 2004
Posts: 201

Post Post subject: Reply with quote

Give me your email address so I can attatch the whole forlder as zip file and send it to you.
_________________
Sarder Hasnut
MCSD, CIW A

Need Low Cost Prefessional Hosting Contact me
Sun Sep 05, 04 10:21 am
Back to top
hasnut View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    dna88 Forum Index -> Web scripting language Discussion Forum All times are GMT - 7 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Partners and Resources

Bangladesh hosting company

Bangladesh web design

Driven by phpBB © phpBB Group