iForum

MMORPG Development Forum
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 How To Setup Random Images [ Signatures ]

View previous topic View next topic Go down 
AuthorMessage
Admin
Admin


Posts: 5
Join date: 2008-12-17

PostSubject: How To Setup Random Images [ Signatures ]   Wed Dec 17, 2008 8:16 am

If you want to setup random sigs or an avatar there are two ways you can go about it. The first way is easier so I'm sure you'll all do it.

EDIT: ** in the code means ] with shift held down (its disabled in here for some reason).

First Method
Go to www.cutandpastescripts.com and signup for an account, then when you've gotten your email from them and logged into the member area go to Random Images under Choose a Script. You have to have your images uploaded somewhere first and you paste the URLs to them on the site. Then they give you a code that looks like this:

Code:
*

Quote:
<!- Random Images Script, by Cut and Paste Scripts. Hosted CGI, with NO adverts and FREE. http://www.cutandpastescripts.com -!><img src="http://www.cutandpastescripts.com/cgi-bin/randomimages/randomimages.pl?username=iouser" alt="Random Images"><!- Copyright Cut and Paste Scripts -!>

*
Pasting that into your sig on here won't work because its HTML no BBcode, so what you have to do is erase everything up to and including <img src=" and everything after and including " alt so you should have something like this now:

Code:
*
Quote:

http://www.cutandpastescripts.com/cgi-bin/randomimages/randomimages.pl?username=iouser

*

Now just put the after and you're all set.

Second Method
This method takes some more time but is worth it as it can do alot more. It envolves using a php script, this script takes an inventory of all the image files in a directory and displays one at random.

What you need to do is copy this script to notepad and save it as a .php file (index.php is recomended but not required) and upload it to a directory that has your images.

To put it in your signature here again just put the URL to the file (or if you named it index.php the folder) in [img] tags and you're done.

Code:
*
Quote:

<?php
if ($dir = opendir(\".\"))
{
$list = buildimagearray($dir);
displayrandomimage($list);
**

// This function reads all the files in the current directory and adds all image files to the array $list[]
function buildimagearray($dir)
{
while (false !== ($file = readdir($dir)))
{
if (!is_dir($file) && getimagesize($file))
{
$list[] = $file;
**
**
return $list;
**

// This function selects a random image, determines the mime type, opens the file for reading,
// and then outputs the image
function displayrandomimage($list)
{
srand ((double) microtime() * 10000000);
$sig = array_rand ($list);

$size = getimagesize ($list[$sig]);
$fp = fopen($list[$sig], \"rb\");

if ($size && $fp)
{
header(\"Content-type: {$size[\'mime\']**\");
fpassthru($fp);
exit;
**
**
?>


*
Modification were made to the code in response to a problem when using PHP version 4.2.2 when array_rand isn't working properly.

The original code (above) is recomended if you don't have this problem, if you do use this one:

Code:
*

Quote:
<?php
if ($dir = opendir(\".\"))
{
$list = buildimagearray($dir);
displayrandomimage($list);
**

// This function reads all the files in the current directory and adds all image files to the array $list[]
function buildimagearray($dir)
{
while (false !== ($file = readdir($dir)))
{
if (!is_dir($file) && getimagesize($file))
{
$list[] = $file;
**
**
return $list;
**

// This function selects a random image, determines the mime type, opens the file for reading,
// and then outputs the image
function displayrandomimage($list)
{
$maxrand = sizeof($list)-1;
$sig = rand(0, $maxrand);

$size = getimagesize ($list[$sig]);
$fp = fopen($list[$sig], \"rb\");

if ($size && $fp)
{
header(\"Content-type: {$size[\'mime\']**\");
fpassthru($fp);
exit;
**
**
?>


*
Comparing Method One to Method Two

The first method though easy is not hosted by you so it can be shutdown, removed, etc. also adding new images in is more of a problem because you have to go through their website each time and upload the images to another site. The second method needs a server with php support (hard to find one without php these days) the advantages to it are that you can have as many random images as you want (different sets) with the first method it's one random image set per account, secondly with the php script you don't have to add files just upload them to your server which you can use an upload script with to make even easier. The php script is a lot more customizable in other ways, you could modify it to say how many times each image has been viewed, almost anything.
Back to top Go down
View user profile http://izone.darkbb.com
 

How To Setup Random Images [ Signatures ]

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» Signatures
» Help with Lexia-3 setup instruction
» Post a Random Image: SpongeBob Edition
» Adding watermark to images in Ubuntu via terminal
» I need Some Icons and Rank Images

Permissions in this forum:You cannot reply to topics in this forum
iForum :: Non-Related MMORPG Sections :: The PortFolio :: Signatures-