All pastes #929186 Raw Edit

RAVATAR v2

public php v1 · immutable
·published 2008-03-05 16:31 UTC
rendered paste body
<?php/** * @name		RAVATAR Random Avatar * @author 		lordfrikk * @copyright 	2008 */function file_ext($filename) // by Abhinandan Jain{        return strtolower(str_replace(".", "", strrchr($filename, ".")));}$dir = dir('./avatars');clearstatcache();while ($file = $dir->read()):	if (file_ext($file) == ('jpg' || 'jpeg' || 'gif' || 'png')):		$files[] = $file;	endif;endwhile;$dir->close();srand((double) microtime() * 1000000);$ravatar 	= $files[mt_rand(0, count($files)-1)]; $filepath 	= sprintf('%s/%s', $dir->path, $ravatar);$ext		= file_ext($ravatar);if ($ext == 'gif'):	$im 	= fopen($filepath, 'r');else:	$im 	= imagecreatefromstring(file_get_contents($filepath));endif;switch ($ext):	case 'jpg':		header('Content-type: image/jpeg');		imageJPEG($im);	break;	case 'jpeg':		header('Content-type: image/jpeg');		imageJPEG($im);	break;	case 'gif':		header('Content-type: image/gif');		fpassthru($im);		fclose($im);	break;	case 'png':		header('Content-type: image/png');		imagePNG($im);	break;endswitch;?>