Web Analytics Made Easy -
StatCounter Random image generator (sorta) WP - CodingForum

Announcement

Collapse
No announcement yet.

Random image generator (sorta) WP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random image generator (sorta) WP

    Hello, (first post, most likely in the wrong place..but,)

    Im hoping someone can help explain the code and implementation, or point me in the right direction. Lets say i would like to have a particular wordpress page created, and on this page is a single container that will randomly generate/pull an image from a folder in my root or within my media uploads. Think iChing or Fortune Telling app. There would be a specific number of labeled images in a folder, and when a button is selected.. an image appears. Recycling the page each time to get a new image is not an option.

    If you want to get really fancy, how about adding a proper transition from start to image, and then back again.

    Anyhow, thanks in advance for any help! :] please do lemme know if more info would help..

  • #2
    I would suggest posting this in the PHP or JavaScript section. From my own experience, PHP and JavaScript are your best bet to make a page that loads images randomly from an external source on the server.

    Comment


    • #3
      Originally posted by Jsl View Post
      Hello, (first post, most likely in the wrong place..but,)

      Im hoping someone can help explain the code and implementation, or point me in the right direction. Lets say i would like to have a particular wordpress page created, and on this page is a single container that will randomly generate/pull an image from a folder in my root or within my media uploads. Think iChing or Fortune Telling app. There would be a specific number of labeled images in a folder, and when a button is selected.. an image appears. Recycling the page each time to get a new image is not an option.

      If you want to get really fancy, how about adding a proper transition from start to image, and then back again.

      Anyhow, thanks in advance for any help! :] please do lemme know if more info would help..
      Originally posted by MrConman View Post
      I would suggest posting this in the PHP or JavaScript section. From my own experience, PHP and JavaScript are your best bet to make a page that loads images randomly from an external source on the server.
      Javascript is only needed for your last bit about 'getting fancy'. Javascript, in my opinion, should be reserved for luxury features only - nothing to do with the running of the site. My reasoning - javascript is executed client side leaving it very much open to malicious user manipulation.

      In terms of the PHP, if you're wanting a random image that, once generated, doesn't change for the person then you could use sessions or cookies (I would use a cookie). The function glob() returns an array of directories and files matching a pattern. So, using that array you would just need to random an index, save that index to a cookie. Your page would check for the cookie - if it exists, use the value to display the image index in glob() and if it doesn't, generate an index, save to cookie and then use that in the glob() generated array.
      Useful function to retrieve difference in times
      The best PHP resource
      A good PHP FAQ
      PLEASE remember to wrap your code in [PHP] tags.
      PHP Code:
      // Replace this
      if(isset($_POST['submitButton']))
      // With this
      if(!empty($_POST))
      // Then check for values/forms. Some IE versions don't send the submit button 
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

      Comment


      • #4
        Thanks guys, much appreciated..

        The image can change, and should change back to the original 'opening/welcome image' if a user leaves the page or refreshes.. that's no big deal. i may have been a bit cryptic (my bad) most of the 'random anything' plugins i have found for WP rely on auto transitions or refreshing to generate another image.. i need a box, with a set opening image, and a button to pull 1 of 64 images from a folder, truly random though. Pretty much just need a button controlled oracle with 64 possibilities.

        Now i simply need someone to write it ?$? :]

        Thanks again!

        Comment


        • #5
          Originally posted by Jsl View Post
          Thanks guys, much appreciated..

          The image can change, and should change back to the original 'opening/welcome image' if a user leaves the page or refreshes.. that's no big deal. i may have been a bit cryptic (my bad) most of the 'random anything' plugins i have found for WP rely on auto transitions or refreshing to generate another image.. i need a box, with a set opening image, and a button to pull 1 of 64 images from a folder, truly random though. Pretty much just need a button controlled oracle with 64 possibilities.

          Now i simply need someone to write it ?$? :]

          Thanks again!
          Now that you've described your problem, it's a javascript solution you require . Or rather, JS will give you a smoother result as it's an image animator. You should take your question there (I do know a bit of JS but not enough to be confident enough to try a solution).
          Useful function to retrieve difference in times
          The best PHP resource
          A good PHP FAQ
          PLEASE remember to wrap your code in [PHP] tags.
          PHP Code:
          // Replace this
          if(isset($_POST['submitButton']))
          // With this
          if(!empty($_POST))
          // Then check for values/forms. Some IE versions don't send the submit button 
          Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

          Comment

          Working...
          X