WP-Syntax Test

by bagheadinc on January 5, 2009

<?php
	$allowed_mimes=array("image/jpeg","image/gif","image/png");
	$dirPath = "./";
	$imglist = array();
	if ($handle = opendir($dirPath)) {
		while (false !== ($file = readdir($handle))) {
			$imageinfo = @getimagesize($file);
			if(in_array($imageinfo["mime"], $allowed_mimes))
				$imglist[] = $file;
		}
		closedir($handle);
	}
 
	$rand = rand(0,count($imglist)-1);
	$file = $imglist[$rand];
	$imageinfo = @getimagesize($file);
 
	switch($imageinfo["mime"]) {
		case "image/jpeg":
			$image = imagecreatefromjpeg($file);
			header("Content-type: image/jpeg");
			imagejpeg($image);
			break;
		case "image/gif":
			$image = imagecreatefromgif($file);
			header("Content-type: image/gif");
			imagegif($image);
			break;
		case "image/png":
			$image = imagecreatefrompng($file);
			imagealphablending($image,false);
			imagesavealpha($image,true);
			header("Content-type: image/png");
			imagepng($image);
			break;
	}
	imagedestroy($image);
?>
blog comments powered by Disqus

Previous post:

Next post: