Generates a random image chosen from a list specified by the user. This script allows the user to set up a list of images in a directory, set image attributes including width, height, border, alignment, and an alt tag, and creates a standard-friendly line of code containing the randomly selected image.
Copy and paste the following into the head () portion of your web page:
directory = "images/"; // The location of your randomized images. // e.g. "images/myPhotos/" images = new Array(); // Leave this line as it is // Fill in the name of the photos in the folder below. // To add more images, follow the model below // images[x] = "PATH/TO/IMAGE"; images = "image1.jpg"; images = "image2.jpg"; images = "image3.jpg"; images = "image4.jpg"; var width = null; // Enter the width of all images in pixels (e.g. 100) var height = null; // Enter the height of all images in pixels (e.g. 50) var border = null; // Enter the border of all images in pixels (e.g. 1) var alignment = null; // Enter "true" to align left; "false" to align right; "null" for no alignment. var alt = ""; // Enter a meaningful description for your image or leave as is (e.g. "my picture")
In this above portion of the code, you may apply your customized settings.
- directory - (line 1) Define the directory that contains all the images. Can be linked to a relative or absolute (if permitted) location.
- image[x] - (line 9-12) Define the file name of the image located in the directory (line 1)
- width - (line 14) Define the width (numerical value) in pixels of the randomly generated image. May be left as null if you prefer not to define one (optimal for multi-sized images).
- height - (line 15) Define the height(numerical value) in pixels of the randomly generated image. May be left as null if you prefer not to define one (optimal for multi-sized images).
- border - (line 16) Define the size of the border around the image. May be left as null if you prefer not to define one.
- alignment - (line 17) Define the type of alignment for the image (in boolean). Use “true” to align left, “false” to align right, or null to invoke no alignment.
- alt - (line 18) Fill in a meaningful description to describe the photo in text in between the quotes.
Apply the following to the location where you would like to generate your random image:
<noscript> <img src="images/image1.jpg" mce_src="images/image1.jpg" width="750" height="250" border="0" alt="" /> </noscript>