Forum     

Go Back   Digit Technology Discussion Forum > Community > Tutorials
Register FAQ Calendar Mark Forums Read

Tutorials This section offers tutorials and How to's on just about anything related to computers and IT. Note: All tutorials are courtesy the posters and not verified by Digit

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 03-09-2005, 11:58 PM   #1 (permalink)
Right Off the Assembly Line
 
wolvrine's Avatar
 
Join Date: Jul 2005
Location: http:404 not found
Posts: 33
Default how to create a random a avtar

To do this used php , the GD library and the most important ingredient the rand() function.

The rand function selects a random number between the 2 numbers you give it.
So rand(1,25) will output a random number between 1 and 25 everytime the script is run. This function is usefull for making any dynamic random content and can be used for many different things.
We are going to use it to select a random image.

Ok, so lets go through the code and see what it does.
Code:
$rand = rand(1, 25);

The first line of our code selects a random number between 1 and 25, so we have the image we are using straight away.

Code:
$image = "$rand.png";

The second line tells the server what image we are going to be using.
Note the use of $rand followed by .png
This creates the name of the image. 1.png up to 25.png

Code:
$im = imagecreatefrompng($image);

The next line tells the server to create an image using the randomly selected png image.

Code:
header("Content-Type: image/png");

The next line is imprtant.
It instructs the persons browser to expect binary data.
If this isnt specified the browser will output text (like you see when you edit a picture in notepad).
With this line the browser knows it is supposed to create an image from the information it recieves.

Code:
Imagepng($im,'',100);
ImageDestroy ($im);

The final two lines create the image and then throw it away.

Now, we should have a script that looks like this
Code:
<?php
$rand = rand(1, 25);
$image = "$rand.png";
$im = imagecreatefrompng($image);

header("Content-Type: image/png");
Imagepng($im,'',100);
ImageDestroy ($im);
?>

If you put that in a folder with 25 images called
1.png
2.png
3.png
all the way up to 25.
Each time the image is loaded it will out put a different image.
wolvrine is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 08-09-2005, 01:44 PM   #2 (permalink)
I am Optimus Prime
 
navjotjsingh's Avatar
 
Join Date: Feb 2005
Location: Delhi, India
Posts: 1,919
Default

Nice tip. Will try it today.
navjotjsingh is offline  
Old 13-09-2005, 06:41 PM   #3 (permalink)
Hanging, since 2004..
 
tarey_g's Avatar
 
Join Date: Aug 2004
Location: hanging..
Posts: 3,253
Default

dosen't work for avatar , burt can be used in sig
__________________
Digit forum without nagging ads and with new features = http://www.thinkdigit.com/forum/showthread.php?p=945285
tarey_g is offline  
Old 18-10-2005, 11:15 PM   #4 (permalink)
deadman
Guest
 
Posts: n/a
Default

By the way, DIGIT is not alowing siggy

so no use in this forum

deadman is here
 
Old 28-01-2009, 10:04 PM   #5 (permalink)
Right Off the Assembly Line
 
Join Date: Jan 2009
Posts: 1
Default Re: how to create a random a avtar

why create random avatar when you can create your own avatar?

http://www.ceveni.com/2009/01/create...tar-using.html
joshna7 is offline  
Old 28-01-2009, 10:53 PM   #6 (permalink)
AFK
 
thewisecrab's Avatar
 
Join Date: Oct 2006
Location: Bombay
Posts: 1,596
Default Re: how to create a random a avtar

WTF!!!
What a historic bump
Reported.......
__________________
Check out http://thefinal3rd.com, an Indian footie blog. Follow me on http://twitter.com/thewisecrab

Fishdumplings!! Duniya goal hai?
thewisecrab is offline  
Old 28-01-2009, 10:56 PM   #7 (permalink)
Sami Hyypiä, LFC legend
 
Liverpool_fan's Avatar
 
Join Date: Jun 2007
Location: Us desh mein jaha Mera Neta Chor Hai
Posts: 1,940
Default Re: how to create a random a avtar

Quote:
Originally Posted by joshna7 View Post
why create random avatar when you can create your own avatar?

http://www.ceveni.com/2009/01/create...tar-using.html
Wow you really have the power to raise the dead back from life.
Raising from the dead is a gift indeed, use it well.
__________________
Read before asking / messaging any moderator for any query: FAQ + answers for new members

Read all the sticky threads before asking any type of query. Most basic questions are answered in those.

Don't use forum for chatting. Visit http://webchat.freenode.net/?channels=krow, enter nick and connect.

"Luck has a peculiar habit of favoring those who don't depend on it."
Liverpool_fan is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

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 On
Refbacks are On



All times are GMT +5.5. The time now is 03:46 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2