There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware missing monitor network networking outlook outlook 2003 outlook 2007 outlook express password popups problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Random image with link


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
ashras99's Avatar
Senior Member with 1,025 posts.
 
Join Date: Jul 2002
Location: India
04-Mar-2008, 06:14 AM #1
Arrow Random image with link
I want a radom image loaded on a webpage through folder, automatically on every refresh. Currently i am using a script http://www.alistapart.com/d/randomizer/rotate.txt

this script is working absolutely great, just i am looking a way to create a link for the image to go on some URL.

Can anyone tell me any other script which is in php?
SNewman's Avatar
Member with 43 posts.
 
Join Date: Feb 2006
Location: New Jersey
Experience: Intermediate
04-Mar-2008, 08:52 AM #2
You can try the script located at http://ma.tt/scripts/randomimage/. It is similar to the previous script you were using, however this one uses standard HTTP headers instead of reading the entire image file like the last script did, thus making it possible to link your image. For example:

Code:
<a href="http://some.url"><img src="rotate.php" alt="A Random Image"></a>
__________________
Scott Newman

Serving n00bz since 2005!
ashras99's Avatar
Senior Member with 1,025 posts.
 
Join Date: Jul 2002
Location: India
04-Mar-2008, 09:01 AM #3
Thanks a lot for the link, but possible to link seperate image for seperate URL?

One one link, we can even link before too.
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
04-Mar-2008, 12:22 PM #4
PHP Code:
<? // The microtime() function returns the current UNIX timestamp, in microseconds
srand((float) microtime() * 10000000);

//next, define images and links in the array
//you can use absolute or full url's, if you need more, add them in the same array as the existing links
//
$image[1]['pic']='banners/image1.jpg';
$image[1]['link']='link1.php#1';

$image[2]['pic']='banners/image2.jpg';
$image[2]['link']='link1.php#2';

$image[3]['pic']='banners/image3.jpg';
$image[3]['link']='link1.php#3';

$image[4]['pic']='banners/image4.jpg';
$image[4]['link']='link1.php#4';

$image[5]['pic']='banners/image5.jpg';
$image[5]['link']='link1.php#5';

//create the statement to show the images
$rn array_rand($image);

//then display the image and link on the page
echo '<a href="'.$image[$rn]['link'].'">';
echo 
'<img src="'.$image[$rn]['pic'].'">';

?>
That should get you what you wanted. Here is a test link on my site to try it out.
ashras99's Avatar
Senior Member with 1,025 posts.
 
Join Date: Jul 2002
Location: India
04-Mar-2008, 12:32 PM #5
Thanks for the code, is this possible in your code to set - only random image on refresh and not automatically load the another image or some fade in transition between them because currently not looking good. Secondly, link blue border also removed from the image.

Can't possible some editing in this script : http://www.alistapart.com/d/randomizer/rotate.txt
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
04-Mar-2008, 12:48 PM #6
Hey, that is exactly what the script does, other than a fade in. If you want fading, you need to use flash or DHTML (with JS)
http://www.dynamicdrive.com/dynamici...nslideshow.htm

The sample page reloads to show you the sample of the randomness of the images loaded, it is not part of the script or intended to be shown.

You can easily remove the blue border by adding border="0" to the code to display the images.
Code:
//then display the image and link on the page
echo '<a href="'.$image[$rn]['link'].'">';
echo '<img src="'.$image[$rn]['pic'].'" border=\"0\">';
Maybe someone can modify your code.
__________________
Good Luck on your fix

My real hobby..JoyCo
My real Job..(Second Hobby) IAFF Local 1865
Like the sites? My hobby is the one that created them!

Last edited by Sequal7 : 04-Mar-2008 05:02 PM.
ashras99's Avatar
Senior Member with 1,025 posts.
 
Join Date: Jul 2002
Location: India
04-Mar-2008, 01:42 PM #7
Thanks, your script works absolutely fine, but i have noticed extra space in bottom 5-6pixels are coming from the actual size of the image, which can destroy the look. You know why those extra pixels are coming and how to avoid?
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
04-Mar-2008, 03:42 PM #8
Can you show me an example?
ashras99's Avatar
Senior Member with 1,025 posts.
 
Join Date: Jul 2002
Location: India
05-Mar-2008, 12:52 AM #9
have a look the sample here: http://chandrarat.com/testshow.php

above only few extra pixels in bottom is coming, but where actually i am trying to place where around 10 pixels are coming.
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
05-Mar-2008, 01:20 AM #10
Actually, it is your table that is doing that, not my script. Remove the &nbsp: from the empty tables and the

Make the table background the same as the page background and that will disappear.

bgcolor="#333333"

You can view your exact page here
ashras99's Avatar
Senior Member with 1,025 posts.
 
Join Date: Jul 2002
Location: India
05-Mar-2008, 03:58 AM #11
thanks a lot, can you tell me what is the meaning of "srand((float) microtime() * 10000000);" in script.

Is this also possible to add in a script to create slideshow of the images in a same way...with link?
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
05-Mar-2008, 05:57 PM #12
Seeding, it instructs the random number generator to find a random number (image) based, in this case, in microseconds.
Microtime() function returns the current UNIX timestamp, PHP micortime() function

Sure, this code could become something more than just a banner image display, but the complexity would grow, and so too would the script.

Maybe you should try something like this;
http://www.maani.us/slideshow/index....Picture_Book_2
__________________
Good Luck on your fix

My real hobby..JoyCo
My real Job..(Second Hobby) IAFF Local 1865
Like the sites? My hobby is the one that created them!
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:18 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.