Can One Generate A Random Image Each Time It’s Viewed? I.e., Asdf.com/1.jpg Appears Different With Each Load?
Written By: RSmaster on May 27, 2009
2 Comments
First of all, filehosting is not an issue at all. I’d like to, if I may, do something like [img]url_to_some_image[/img] in a forum and have this pick an image out of an album of images and display it each time that image url is requested by the page. Can this be done? I’ve seen ways to do this kind of thing with javascript on the page it’s used, but I really need to be able to do this from the other side of the exchange. Anyone able to help? thx.
Tags: Appears, Asdf.com/1.jpg, Each, Generate, I.e., Image, It's, Random, Time, Viewed









Depends on the language available on the server (Php, ASP etc).
Here is how I do it for PhP.
1. Create your image names in the same way, but with a number at the end, i.e. “img1.jpg”, “img2.jpg”, … , “img20.jpg”.
2. When loading the page, your code is as follow:
< ?php
echo "< img src = 'img" . rand ( 1 , 20 ) . ".jpg ' >“;
?>
PhP will form the names img#.jpg each time it is called, at random, from img1.jpg to img20.jpg
This can be done but you have to get pretty heavily into web development and have a clear understanding of server side processing an file types and how they interact.
If you were really determined to do it from the server side, you could create a site that was configured in IIS (or apache or whatever) to process files with the ,gif extension as if they were .asp files(or .aspx or pick any other ISAPI application). Then create a myImage.gif file in notepad with asp code in it. With the first line of the code you can set the ContentType back to gif and then output raw data (aka a binary stream of x or y image) to the screen. When the server that your forum is hosted on gets the image it has the proper extension and is formatted just like any other image. It would never know the difference.
Depending on how your forum is set up you might not have to change all your ISAPI filter stuff. Last time I was generating dynamic images on the server side I just put “http://myaddress.com/graph.asp” in the source attribute for the image. It displays just like any other image as long as you changed Response.ContentType in the graph.asp file. There is a good chance you won’t be able to put a .asp into an IMG tag on your forum though. Security and all that that.
Give this tutorial a try for a better explanation of what I’m talking about. If you don’t have much experience in server side web development this stuff will probably be way over your head.http://www.15seconds.com/issue/990923.ht...