Previous Section  < Day Day Up >  Next Section

Hack 51. Browse the World Wide Photo Album

Take a random stroll through the world's photo album using some clever Google Image searches (and, optionally, a smidge of programming know-how).

The proliferation of digital cameras and growing popularity of camera phones are turning the Web into a worldwide photo album. It's not only the holiday snaps of your Aunt Minnie or minutiae of your moblogging friend's day that are available to you. You can actually take a stroll through the publicly accessible albums of perfect strangers if you know where to look. Happily, Google has copies, and a couple of hacks know just where to look.

3.5.1. Random Personal Picture Finder

Digital photo files have relatively standard filenames (e.g., DSC01018.JPG) by default and are usually uploaded to the Web without being renamed. The Random Personal Picture Finder (http://www.diddly.com/random) sports a clever little snippet of JavaScript code that simply generates one of these filenames at random and queries Google Images for it.

The result, shown in Figure 3-3, is something like looking through the world's photo album: people eating, working, posing, and snapping photos of their cats, furniture, or toes. And since it's a normal Google Images search, you can click on any photo to see the story behind it, and the other photos nearby.

Neat, huh?

Figure 3-3. The Random Personal Picture Finder


Note that people snap pictures of not just their toes (or the toes of others). While an informal series of Shift-Reloads in my browser turned up only a couple of questionable bits of photographic work, you should assume the results are not workplace- or child-safe.


The code behind the scenes, as I mentioned, is really very simple—a swatch of JavaScript (view the source of http://www.diddly.com/random/random.html in your browser to see the JavaScript bits for yourself) and list of camera types and their respective filename structures (http://www.diddly.com/random/about.html). You're simply redirected to Google Images with generated search query in tow.

A smidge of Python illustrates just how simple it is to generate a link to some random collection of photos shot with a Canon digital camera:

$ python

Python 2.3 (#1, Sep 13 2003, 00:49:11) 

[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> from random import randint

>>> linkform = 'http://images.google.com/images?q=IMG_%s.jpg'

>>> print linkform % str(randint(1, 9999)).zfill(4)

http://images.google.com/images?q=IMG_7931.jpg

You can easily use this as the basis of a CGI script that acts in the same manner as the Random Personal Picture Finder does.

3.5.2. WebCollage

And if you think the Random Personal Picture Finder is fun, you'll love Jamie Zawinski's WebCollage (http://www.jwz.org/webcollage/), a Perl script that finds random pages, strips them of their images, and puts these images together to create a collage. The collage is remixed and added to once a minute, your browser reloading a fresh version every so often (or just hit Shift-Reload on your browser yourself to speed up the process). Figure 3-4 shows a WebCollage snapshot in time.

Figure 3-4. A typical WebCollage snapshot of random pictures gleaned through Internet search


Click on any one element and you'll be taken to the page that the image is from.

You can grab the Perl source (http://www.jwz.org/webcollage/webcollage) and generate a page similar to Jamie's like so:

$ webcollage -size '800x600' -imagemap 

~/public_html/collage

where 800x600 is the size and ~/public_html/collage is the path to and file you'd like to save the image map as.

WebCollage is also included in Zawinski's XScreenSaver (http://www.jwz.org/xscreensaver), a screensaver system for computers running the X Windows System (usually some brand of Unix).

As Jamie notes, he's disabled the Google search in WebCollage (you can just uncomment it in your own downloaded version) because it's not a Google API-based application and so is not in keeping with Google's Terms of Service ["A Note on Spidering and Scraping" in Chapter 9]. You can, however, very easily write a Google-specific API-friendly version.


Aaron Swartz

    Previous Section  < Day Day Up >  Next Section