Revision: 3690
Updated Code
at March 19, 2008 08:13 by pitje
Updated Code
/* rotating avatars create a directory on your webserver, call it avatars and put a few avatars in it, along with this file. (index.php) ( make sure the avatars are about the same size, and preferably square ( width == height ) ) check http://www.yourdomain.com/avatars/ to see the result. Refresh the page to see another avatar. */ function listImages ( )//reads images in current directory, returns array with filenames { $allowed_extensions = array ( ".jpg", ".png", ".gif" ); $dir = opendir ( getcwd ( ) ); while ( $file = readdir ( $dir ) ) { $extension = strtolower ( substr ( $file, strlen ( $file ) - 4, strlen ( $file ) ) ); if ( in_array ( $extension, $allowed_extensions ) ) $linklist[] = $file; } closedir ( $dir ); return $linklist; } function mkImg ( $file, $ftype )//returns an image with filetype $ftype, sourceimage is $file { $img = imagecreatefromstring ( file_get_contents ( $file ) ); switch ( $ftype ) { case ".jpg": header('Content-Type: image/jpg'); imagejpeg($img); break; case ".gif": header('Content-Type: image/gif'); imagegif($img); break; case ".png": default: header('Content-Type: image/png'); imagepng($img); break; } } //read the images in the current directory $images = listImages ( ); //pick a random one $rnd = $images[array_rand ( $images )]; //for use on forums -> link to /path/to/index.php?ftype=.jpg (fools SOME forum software into thinking it's a jpg) $ftype = $_REQUEST['ftype'] ? $_REQUEST['ftype'] : ".png"; //return the randomly picked image mkImg ( $rnd, $ftype );
Revision: 3689
Updated Code
at September 2, 2007 06:41 by pitje
Updated Code
/* rotating avatars create a directory on your webserver, call it avatars and put a few avatars in it, along with this file. (index.php) ( make sure the avatars are about the same size, and preferably square ( width == height ) ) check http://www.yourdomain.com/avatars/ to see the result. Refresh the page to see another avatar */ function listImages ( )//reads images in current directory, returns array with filenames { $allowed_extensions = array ( ".jpg", ".png", ".gif" ); $dir = opendir ( getcwd ( ) ); while ( $file = readdir ( $dir ) ) { $extension = strtolower ( substr ( $file, strlen ( $file ) - 4, strlen ( $file ) ) ); if ( in_array ( $extension, $allowed_extensions ) ) $linklist[] = $file; } closedir ( $dir ); return $linklist; } function mkImg ( $file, $ftype )//returns an image with filetype $ftype, sourceimage is $file { $img = imagecreatefromstring ( file_get_contents ( $file ) ); switch ( $ftype ) { case ".jpg": header('Content-Type: image/jpg'); imagejpeg($img); break; case ".gif": header('Content-Type: image/gif'); imagegif($img); break; case ".png": default: header('Content-Type: image/png'); imagepng($img); break; } } //read the images in the current directory $images = listImages ( ); //pick a random one $rnd = $images[array_rand ( $images )]; //for use on forums -> link to /path/to/index.php?ftype=.jpg (fools the forum software into thinking it's a jpg) $ftype = $_REQUEST['ftype'] ? $_REQUEST['ftype'] : ".png"; //return the randomly picked image mkImg ( $rnd, $ftype );
Revision: 3688
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 2, 2007 03:39 by pitje
Initial Code
/* rotating avatars create a directory on your webserver, call it avatars and put a few avatars in it, along with this file. (index.php) ( make sure the avatars are about the same size, and preferably square ( width == height ) ) check http://www.yourdomain.com/avatars/ to see the result. Refresh the page to see another avatar */ function listImages ( )//reads images in current directory, returns array with filenames { $allowed_extensions = array ( ".jpg", ".png", ".gif" ); $dir = opendir ( getcwd ( ) ); while ( $file = readdir ( $dir ) ) { $extension = strtolower ( substr ( $file, strlen ( $file ) - 4, strlen ( $file ) ) ); if ( in_array ( $extension, $allowed_extensions ) ) $linklist[] = $file; } closedir ( $dir ); return $linklist; } function mkImg ( $file, $ftype )//returns an image with filetype $ftype, sourceimage is $file { $img = imagecreatefromstring ( file_get_contents ( $file ) ); switch ( $ftype ) { case ".jpg": header('Content-Type: image/jpg'); imagejpeg($img); break; case ".gif": header('Content-Type: image/gif'); imagegif($img); break; case ".png": header('Content-Type: image/png'); imagepng($img); break; } } //read the images in the current directory $images = listImages ( ); //pick a random one $rnd = $images[array_rand ( $images )]; //for use on forums -> link to /path/to/index.php?ftype=.jpg (fools the forum software into thinking it's a jpg) $ftype = $_REQUEST['ftype'] ? $_REQUEST['ftype'] : ".png"; //return the randomly picked image mkImg ( $rnd, $ftype );
Initial URL
http://www.poehey.nl/media/img/avatars/
Initial Description
have more than 1 avatar
Initial Title
rotating avatars
Initial Tags
Initial Language
PHP