Jump to content
xisto Community
Sign in to follow this  
pyost

Script For Viewing A Random Image Needed

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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. :D

 

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.