Check out the comments on the manual page for [man]opendir[/man]. There are a couple of implementations of recursive directory iterators there. Alternatively, if you're using PHP5 you can use the RecursiveDirectoryIterator.
Once you have a way of recursively iterating your directories you need a way of extracting jut the image files. The simplest way is to work by the file's extension.
if(preg_match('/\.(gif|jpe?g|png|bmp)$/', $file_name)) {
echo("It's an image");
} else {
echo("It's not an image");
}