Sig Rotator from Anulien
Anulien
Random image PHP script that makes the baby jesus smile.
The script and images have to be hosted on a webserver. In it's current form it will not work with something like photobucket hosted images. But even then the script itself would have to be hosted for you.
Avatars and sigs work the same way. Here is what I would do: name the script avatar.php and create a folder named avatars. Put all your avatar images inside this directory. Inside the avatar.php script change the $imgdir variable to "./avatars/". Now on whatever forum just set your avatar image to http://www.whateverdomain.com/avatar.php and you win life.
The code you put in your sig is similar to the avatar one :
example:
[img]http://whateveryourdoman.com/images.php[/img]You can make a separate folder if images is being used already. Example, Sigs. Make your code changes here
//set image directory to scan, default is ./image/
$imgdir="./image/"; and here $mime_type="image/gif";
break;
case 'jpg':
$mime_type="image/jpg";
break;
case 'jpeg':
$mime_type="image/jpg";
break;
case 'bmp':
$mime_type="image/bmp";
break;
case 'png':
$mime_type="image/png";
break;
. Change image to whatever you named your folder that your sigs are coming out of.
<?php
/*
imgsrv.php - returns random images on request
Author: MC Motherfuckin Anulien the Super Bard of Solusek Ro
imgdir can be absolute or relative path, just keep the trailing slash
Windows ex. C:\wwwroot\image-dir
Linux ex. /home/person/public_html/imagedir/
Or you can leave the default and just create an image directory in the same path as the script
Passing argument i will set the image to the number in the indexed array, for example:
http://domain/imgsrv.php?i=1
will always produce the same image
TODO:
Realign image array based on creation date so adding new images does not change the index,
current allignment is based on alpha ordering
*/
//set image directory to scan, default is ./image/
$imgdir="./image/";
//create and set userland variables
$img_array=array();
$counter=0;
$maxfile=0;
$img_set=-1;
//check if a static index number has been passed in the request
if(isset($_REQUEST["i"]) && $_REQUEST["i"] != '') {
$img_set=$_REQUEST["i"];
}
//scan $imgdir for all files
if ($handle = opendir($imgdir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$img_array[$counter]=$file;
$counter++;
}
}
closedir($handle);
}
//set file count for the image array
$maxfile=count($img_array)-1;
//if an index number has passed select the image matching that array index
if ($img_set == -1) {
$imgfile=$img_array[rand(0,$maxfile)];
} else {
$imgfile=$img_array[$img_set];
}
/*
kludge: do not use file names with more than one . till i stop being lazy and write some regex
the kludge is to avoid having to enable magic mime, fuck that noise
*/
$ext = substr(strrchr($imgfile, "."), 1);
switch ($ext) {
case 'gif':
$mime_type="image/gif";
break;
case 'jpg':
$mime_type="image/jpg";
break;
case 'jpeg':
$mime_type="image/jpg";
break;
case 'bmp':
$mime_type="image/bmp";
break;
case 'png':
$mime_type="image/png";
break;
}
//create file pointer with read only permissions
$fp=fopen($imgdir.$imgfile,"r");
//pass image headers and length. meets browser RFC requirements
header("Content: ".$mime_type);
header("Content-Length: ".filesize($imgdir.$imgfile));
//pass memory of set file pointer
fpassthru($fp);
//close current file pointer to prevent memory leaks, never trust high level languages!
fclose($fp);
?>
Rikr
21 years ago
How do you make this work? do you use [code] or just plug the php in your sig box?
Verileah
21 years ago
I know you explained how to do avatars with this script...but I forgot :(. If you could 'splain I would appreciate it greatly.
Anulien
21 years ago
Rikr, the script and images have to be hosted on a webserver. In it's current form it will not work with something like photobucket hosted images. But even then the script itself would have to be hosted for you.
Veri, avatars and sigs work the same way. Here is what I would do: name the script avatar.php and create a folder named avatars. Put all your avatar images inside this directory. Inside the avatar.php script change the $imgdir variable to "./avatars/". Now on whatever forum just set your avatar image to http://www.whateverdomain.com/avatar.php and you win life.
Veri, avatars and sigs work the same way. Here is what I would do: name the script avatar.php and create a folder named avatars. Put all your avatar images inside this directory. Inside the avatar.php script change the $imgdir variable to "./avatars/". Now on whatever forum just set your avatar image to http://www.whateverdomain.com/avatar.php and you win life.
Verileah
21 years ago
I think I lose at life actually :(.
Anulien
21 years ago
For those having problems, try this:
<?php
/*
imgsrv.php - returns random images on request
Author: MC Motherfuckin Anulien the Super Bard of Solusek Ro
imgdir can be absolute or relative path, just keep the trailing slash
Windows ex. C:\wwwroot\image-dir
Linux ex. /home/person/public_html/imagedir/
Or you can leave the default and just create an image directory in the same path as the script
Passing argument i will set the image to the number in the indexed array, for example:
http://domain/imgsrv.php?i=1
will always produce the same image
TODO:
Realign image array based on creation date so adding new images does not change the index,
current allignment is based on alpha ordering
*/
//set image directory to scan, default is ./image/
$imgdir="./image/";
//create and set userland variables
$img_array=array();
$counter=0;
$maxfile=0;
$img_set=-1;
//check if a static index number has been passed in the request
if(isset($_REQUEST["i"]) && $_REQUEST["i"] != '') {
$img_set=$_REQUEST["i"];
}
//scan $imgdir for all files
if ($handle = opendir($imgdir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$img_array[$counter]=$file;
$counter++;
}
}
closedir($handle);
}
//set file count for the image array
$maxfile=count($img_array)-1;
//if an index number has passed select the image matching that array index
if ($img_set == -1) {
$imgfile=$img_array[rand(0,$maxfile)];
} else {
$imgfile=$img_array[$img_set];
}
/*
kludge: do not use file names with more than one . till i stop being lazy and write some regex
the kludge is to avoid having to enable magic mime, fuck that noise
*/
$ext = substr(strrchr($imgfile, "."), 1);
switch ($ext) {
case 'gif':
$mime_type="image/gif";
break;
case 'jpg':
$mime_type="image/jpg";
break;
case 'jpeg':
$mime_type="image/jpg";
break;
case 'bmp':
$mime_type="image/bmp";
break;
case 'png':
$mime_type="image/png";
break;
}
//create file pointer with read only permissions.
//added binary mode for some windows problems
$fp=fopen($imgdir.$imgfile,"rb");
//pass image headers and length. meets browser RFC requirements
header("Content-Type: ".$mime_type);
header("Content-Length: ".filesize($imgdir.$imgfile));
//pass memory of set file pointer
fpassthru($fp);
//close current file pointer to prevent memory leaks, never trust high level languages!
fclose($fp);
?>