Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Script For Viewing A Random Image Needed
pyost
post Aug 28 2006, 12:19 PM
Post #1


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,013
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



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

CODE
<img src="http://www.greenplastic.com/images/v75/random/random.php" 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:

CODE
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.
Go to the top of the page
 
+Quote Post
vujsa
post Aug 28 2006, 01:22 PM
Post #2


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714



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://www.ilovejackdaniels.com/apache/
The cheat sheet there is very helpful.

Basically, here is the deal. I request www.domain.com/directory/image.png and the server accesses www.domain.com/directory/image.php instead.

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

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:
CODE
RewriteEngine on

RewriteRule ^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:
CODE
RewriteEngine on

RewriteRule ^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. ohmy.gif

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

RewriteRule ^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. cool.gif

vujsa
Go to the top of the page
 
+Quote Post
pyost
post Aug 28 2006, 04:54 PM
Post #3


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,013
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



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 tongue.gif 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.
Go to the top of the page
 
+Quote Post
vhortex
post Aug 28 2006, 09:26 PM
Post #4


Guilty Until Proven Innocent
Group Icon

Group: Members
Posts: 372
Joined: 13-April 05
Member No.: 3,937



QUOTE(pyost @ Aug 29 2006, 12:54 AM) *

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 tongue.gif 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.. https://admin.maldivesliveaboards.com/includes/random.php
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..
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Help With Some Php Or Maybe Asp(5)
  2. Trainable Anti-spam Filter Script(3)
  3. Php Script To Download File From Another Site(9)
  4. Need Help With A PHP - MySQL Registration Script(13)
  5. What Would Make A Good Registration Script?(4)
  6. Basics Of Php For Beginners - Suggestion(5)
  7. Automatic/remote Php Script Execution(9)
  8. Coders Needed To Help On A Bulletin Board System (BBS)(4)
  9. Something Wrong With This Script?(9)
  10. Automated Product Suggestion Script(2)
  11. Run A Script When Expires A Session(6)
  12. Php Script Help(1)
  13. Need Help With Background Image...(12)
  14. SQL Doesn't Connect In PHP Script(19)
  15. Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...(4)
  1. Password Recovery Script(6)
  2. Login Script(8)
  3. Free Forum Hosting Type Script Help!(2)
  4. Script Request(2)
  5. Image Popup On Mouseover(23)
  6. Writing And Testing My Own Login Script [solved](20)
  7. Make A Script Run Even If No User Is Online(6)
  8. Random With Functions?(4)
  9. Dynamic Gd Image(2)
  10. Php Login Script(0)
  11. Dynamic Php Image And Better Php Code Question(10)
  12. Myspacetv Download Php Script Help(6)
  13. Php Random Selector(2)


 



- Lo-Fi Version Time is now: 14th October 2008 - 04:47 AM