SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Random Images

  1. #1
    Village Idiot cgustaveson's Avatar
    Join Date
    May 2008
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking Random Images

    Does anyone know of any java script application that can pull random images from a directory with multiple incidences?

    The main goal would be to have them displayed on other webpages as well but I would like to be able to pull one image out randomly then selected from only the available images that are not being displayed so for example i have 1.jpg 2.jpg and 3.jpg for spot one 3.jpg is used, so slot two can only use 2.jpg and 1.jpg.

    Any help with this would be greatly appreciated.

    EDIT: I almost forgot I would like to have a different link associated with different images. So that 1.jpg links to 1.com while 2.jpg links to 2.com etc.
    Smoke Lounge | Hookah Store and Community
    Shisha Tobacco
    SitePoint Users get 5% off use promo code s1t35p

  2. #2
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you could do this pretty simply by using a random number generator to create the name of the file that you are trying to link to.

    You would have to be conscious of your naming convention, but you wouldn't even really have to stick to only numbers. You add all the files in the directory into an array and then randomly pick an index to use with the array.
    Stair Lifts & Residential Dumbwaiters, source of health news

  3. #3
    Village Idiot cgustaveson's Avatar
    Join Date
    May 2008
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HeathMan View Post
    I think you could do this pretty simply by using a random number generator to create the name of the file that you are trying to link to.

    You would have to be conscious of your naming convention, but you wouldn't even really have to stick to only numbers. You add all the files in the directory into an array and then randomly pick an index to use with the array.
    I wish I knew javascript, but i don't. I understand a little of what you are saying, I have found one that seems to work but i cant figure out if i can associate links with it.

    The link to the script is here http://www.abcpchelp.com/multiple-ra...php-script.php this is I realize this php but it might work if I can figure out how to associate a link with the image.
    Smoke Lounge | Hookah Store and Community
    Shisha Tobacco
    SitePoint Users get 5% off use promo code s1t35p

  4. #4
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do not have too much time right now, but will try to get back here tomorrow. I am not sure you will be able to find a ready made solution to this problem, and think it will require you do some coding.

    The code you posted follows the general process I described, but in order for it to work for both links and images, you will want to store the name of the file minus the extension.

    For instance
    PHP Code:
    $images=array( // list of files to rotate - add as needed 
     
    "bomb.gif"
     
    "frown.gif"
     
    "grim.gif"
     
    "smile.gif" ); 
    Would Become
    PHP Code:
    $images=array( // list of files to rotate - add as needed 
     
    "bomb"
     
    "frown"
     
    "grim"
     
    "smile" ); 
    Then when you use an element, you could append either .gif or .com to the name before writing it. This would work as long as the file name is the same as the domain name.
    Stair Lifts & Residential Dumbwaiters, source of health news

  5. #5
    Village Idiot cgustaveson's Avatar
    Join Date
    May 2008
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HeathMan View Post
    I do not have too much time right now, but will try to get back here tomorrow. I am not sure you will be able to find a ready made solution to this problem, and think it will require you do some coding.

    The code you posted follows the general process I described, but in order for it to work for both links and images, you will want to store the name of the file minus the extension.

    For instance
    PHP Code:
    $images=array( // list of files to rotate - add as needed 
     
    "bomb.gif"
     
    "frown.gif"
     
    "grim.gif"
     
    "smile.gif" ); 
    Would Become
    PHP Code:
    $images=array( // list of files to rotate - add as needed 
     
    "bomb"
     
    "frown"
     
    "grim"
     
    "smile" ); 
    Then when you use an element, you could append either .gif or .com to the name before writing it. This would work as long as the file name is the same as the domain name.
    I see what your getting at!

    Thanks for the help I will be checking back often.
    Smoke Lounge | Hookah Store and Community
    Shisha Tobacco
    SitePoint Users get 5% off use promo code s1t35p

  6. #6
    Village Idiot cgustaveson's Avatar
    Join Date
    May 2008
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would the above method be too much if there were thousands of images?

    Would it be better to use some sort of mysql for that instead?
    Smoke Lounge | Hookah Store and Community
    Shisha Tobacco
    SitePoint Users get 5% off use promo code s1t35p

  7. #7
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cgustaveson View Post
    Would the above method be too much if there were thousands of images?

    Would it be better to use some sort of mysql for that instead?
    Yeah I think you probably would be better off using mysql. You wouldn't have to worry about naming the pictures the same as the website, which if your talking thousands would probably take some time and I think coding it that way would be a lot easier.
    Stair Lifts & Residential Dumbwaiters, source of health news

  8. #8
    Village Idiot cgustaveson's Avatar
    Join Date
    May 2008
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so I have everything up and running, the site works and all but I to display it on other websites I have to use an iframe of a page that has nothing but one of the random images, is there a way for me to do this with javascript as well so people can choose which format they can use?
    Smoke Lounge | Hookah Store and Community
    Shisha Tobacco
    SitePoint Users get 5% off use promo code s1t35p

  9. #9
    Village Idiot cgustaveson's Avatar
    Join Date
    May 2008
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anybody know how?
    Smoke Lounge | Hookah Store and Community
    Shisha Tobacco
    SitePoint Users get 5% off use promo code s1t35p

  10. #10
    Village Idiot cgustaveson's Avatar
    Join Date
    May 2008
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a way to show a webpage like an iframe with javascript?

    Something that will make people less shy, cause I know some people run from iframes.
    Smoke Lounge | Hookah Store and Community
    Shisha Tobacco
    SitePoint Users get 5% off use promo code s1t35p


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •