DIGIT-ARC read-only archive · snapshot: July 23, 2026

Avtar

23 posts · originally from https://geek.digit.in/community/threads/avtar.90649/

hjpotter92
hjpotter92 Original post #1
Jun 16, 2008 at 6:09 PM
There is another topic for it but I didn't found it for three pages so I created it. I wanted to ask that I got a news about the avtars being changed everytime you refresh your page. It has a bit of coding. So what is it? Is it right that the avtars do change on their own?
praka123
Jun 16, 2008 at 6:15 PM
did u meant GIF?
hjpotter92
Jun 16, 2008 at 6:19 PM
Of course not It is only a bit of Image Ready. I am saying about coding. It is I think to be some special coding. I hope i didn't misread.
Krazzy Warrior
Jun 16, 2008 at 6:23 PM
do u mean for Animation ?
Write clearly.
QwertyManiac
Jun 16, 2008 at 6:25 PM
A random image choosing PHP script?

*ma.tt has a small implementation.
hjpotter92
Jun 16, 2008 at 6:33 PM
A random image choosing PHP script?

*ma.tt has a small implementation.

Yes,it must be a PHP script. as for the link it doesn't open forme. I don't know the reason.
victor_rambo
Jun 16, 2008 at 6:33 PM
^But you can't do it on this forum because the avatar manager downloads the remote image to the server and serves the avatar from there!
hjpotter92
Jun 16, 2008 at 6:35 PM
OMG, it is really a problem forme then. But stil the coding would help me a lot.
QwertyManiac
Jun 16, 2008 at 6:37 PM
PHP:
<?php
/*
By Matt Mullenweg > *photomatt.net
Inspired by Dan Benjamin > *hiveware.com/imagerotator.php
Latest version always at:
*photomatt.net/scripts/randomimage
*/// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder = '';

// Space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';

$files = array(); $i = -1; // Initialize some variables
if ('' == $folder) $folder = './';

$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
$files[] = $file; // it’s good
++$i;
}
}
}
closedir($handle); // We’re not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along

header('Location: '.$folder.$files[$rand]); // Voila!
?>

Usage:
For the simplest possible installation, just drop this code in a directory with the images you want to rotate, and call it like you would a normal image, for example:

<img src="/dropbox/2003/rotate/rotate.php" alt="A Random Image" />
hjpotter92
Jun 16, 2008 at 6:44 PM
But how would I load it as AVTAR on to my account? <_>
QwertyManiac
Jun 16, 2008 at 6:48 PM
I do not know, look into your forum's avatar mechanisms probably and modify them as you wish.
hjpotter92
Jun 16, 2008 at 6:52 PM
OKI got it. Now look at it:
*www.johnbeak.cz/gfx/avatars/change.php
dheeraj_kumar
Jun 16, 2008 at 7:01 PM
I want to ask about a similar thing... check this out...

*chandras.com.au/x0r/randomimage.png

the link is *chandras.com.au/x0r/randomimage.png, ends in a png extention. how about that?

ps: reload the image to get different images
victor_rambo
Jun 16, 2008 at 7:06 PM
^Its the same thing as CAPTCHA except for the background!
QwertyManiac
Jun 16, 2008 at 8:34 PM
Yes it serves a random image every request I suppose.
dheeraj_kumar
Jun 16, 2008 at 9:03 PM
Ok, so is it possible to do it in a wordpress blog? Any script to randomize images every request?
hjpotter92
Jun 17, 2008 at 9:35 PM
It only changes the color but doesn't like the one JOHN BEAK has done.
QwertyManiac
Jun 17, 2008 at 10:21 PM
And also a wrong spelling.
Faun
Faun #20
Jun 17, 2008 at 10:42 PM
^^ZOMG
nitpicking

the link is *chandras.com.au/x0r/randomimage.png, ends in a png extention. how about that?
isn't it just a mapping ?

like we do in JSP
dheeraj_kumar
Jun 18, 2008 at 5:47 PM
Rohan, can you tell us how to do it in wordpress blog?
victor_rambo
Jun 18, 2008 at 6:27 PM
There is actually no need to modify any WP files for that. You can do that with javascript too, but I will discuss here how its done with PHP:

There is actually no need to modify any WP files for that. You can do that with javascript too, but I will discuss here how its done with PHP:
PHP:
//put names of all images you want to rotate randomly
$image_set=array("img1.jpg","img2.jpg","img3.jpg","img4.jpg");

//now select any one random image
$randomly_selected_image=$image_set[array_rand($image_set,1)];

//now fetch the image and store it in a string
$image=file_get_contents("images/$randomly_selected_image");

//send a header to the browser telling it that we are now sending an image
header("Content-type: image/jpg");

//now send the image. 
echo $image;

/*
Because we informed the browser earlier that we are sending an image, it could parse that string as an image.
Else it gets confused and parses it as plain text which looks horrible(with all question marks and rhombuses and weird characters-like the one when fonts are missing!)
*/

Now you can save this file as randomimage.php on yourserver. The HTML markup for your posts would be
Code:
<img src="randomimage.php" alt="random image" title="This image has been generated randomly and will change on refreshing">
Thats how simple it is!
hjpotter92
Jun 19, 2008 at 11:34 AM
Yeah! it is ismple for those who know something about PHP script not me.