HOME       >>       Programming

Script For Viewing A Random Image Needed


pyost

While browsing the web, I bumped into a script that I could really use, since it's different from everything that I saw. Most scripts that view a random image contain a code that chooses an image, and then puts the <img> part into the page itself. However, on the http://www.greenplastic.com/ web site (dedicated to Radiohead), in the top left corner there is a random image module. If you look at the code, here's what is used:

<img src="http://forums.xisto.com/no_longer_exists/; width="125" height="125" />

Now, how can a PHP script be an image, and what kind of script that is? If you do visit that URL, you don't get a normal page, but a radom image. Keep refreshing the page and you'll see what I'm talking about.

As for why I need this script and not one that uses the first mentioned method, it's quite simple. I want the random image to be used for a background, and that code will be entered in the CSS file. So, I want something like this:

module { background: #191919 url(images/random/random.php) no-repeat top left;}

I hope you get the point. If anyone could point me to a script like this, I would be very grateful.

vujsa

As long as the header information is correct when sent to the browser, the image should appear correctly even if it is a PHP file. This isn't alway true and since it is in your CSS, you probably won't validate because you are using an unknow file extention for a known file type.

 

mod_rewrite can fix the file extention for you though. Notice my signature image. It is PHP generated on the fly. The data it uses is statice currently but the images is refreshed as often as every 20 seconds if the file is requested that often.

 

Here is a very good resouce for mod_rewrite:

http://forums.xisto.com/no_longer_exists/

The cheat sheet there is very helpful.

 

Basically, here is the deal. I request http://forums.xisto.com/no_longer_exists/ and the server accesses http://forums.xisto.com/no_longer_exists/ instead.

 

This is how we have those nice HTML file names for all of the pages here at Xisto even though everything is PHP driven here.

 

Just set your program up in it's own directory and name it something rather unique like bgimage.php

Then if you don't already have one in that directory, create a .htaccess file.

In that .htaccess file add the following code:

RewriteEngine onRewriteRule ^bgimage.png$ bgimage.php
This would start the script bgimage.php when the file bgimage.png is requested.

 

For a more dynamic program, you can also pass variable with the rewrite like so:

RewriteEngine onRewriteRule ^background_image([A-Za-z0-9-]{1,})\.jpg$ bg_generator.php?time=$1
This would start the script bg_generator.php when the file background_image325ads123.png is requested where 325ads123 = time!

 

Then with $_GET['time'], you could use the timestamp to control what kind of image is shown. Basically, you could have a dark background at night and a light background during the day. Of course, you can't do that in your CSS file since there isn't a way to insert a timestamp in CSS files.

 

Always be sure to leave at least one blank line at the bottom of your .htaccess file to allow your cPanel to insert code if needed.

 

Another thing that is possible with this is to serve a different CSS everytime.

 

You could either generate a CSS file on the fly with PHP or have several that would rotate.

RewriteEngine onRewriteRule ^default\.css$ css_rotator.php
Then requesting default.css from any page would access the script css_rotator.php which could either create a brand new CSS file or select one from a list. If you were to generate a ne CSS, then you would probably set up a few color schemes and that could be substituted.

 

 

As for what kind of script to use, you can either writ your own or look in the forum for signature rotators. There are a couple of tutorials in here somewhere. I could help you develope your own if you wish.

 

Hope This Helps.

 

vujsa


pyost

I think mod_rewrite could help me, since the PHP extension won't work in CSS. Just to see if I got it all: I put "image.gif" in the CSS file, but mod_rewrite redirects it to image.php, so I get the php file, right?You said that the image in your signature works the same way, but it serves a PNG image, while I need a PHP image. Sort of As for the script, I'll se if there's something on the net. If there isn't, I'll be sure to ask you for help.


vhortex

I think mod_rewrite could help me, since the PHP extension won't work in CSS. Just to see if I got it all: I put "image.gif" in the CSS file, but mod_rewrite redirects it to image.php, so I get the php file, right?
You said that the image in your signature works the same way, but it serves a PNG image, while I need a PHP image. Sort of As for the script, I'll se if there's something on the net. If there isn't, I'll be sure to ask you for help.



some people do draw the images on the fly.. using fast server processors.. it is possible to draw complex graphics.. some just copy an image file into an output stream with a header type of image..

try this one.. one of my scripts.. http://forums.xisto.com/no_longer_exists/
the script generates random chars and draws it into an image..

i have complex image drawings.. one of them was used in an ecommerce shopping cart.. the script generates thumbnails every time you view them and the output is being stored in your local pc.. not good way but it saved space from the server and removes the burden of incomplete data writes when there are a lot of people viewing a certain product and requesting thumbnails..


VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.