<?php $dirname = dirname($_SERVER['SCRIPT_FILENAME']); // get the files in the same dir as this script. $files = scandir($dirname); // filter for only .jpg files foreach($files as $file){ if(substr($file,-4) == ".jpg") $pictures[] = $file; } // pick the random file $rfile = $pictures[mt_rand(0,count($pictures) - 1)]; header("Content-type: image/jpeg"); // resize if we need to if(isset($_GET['size'])) passthru("convert -resize {$_GET['size']}x{$_GET['size']} $rfile jpg:-"); else passthru("cat " . $rfile );?>