Help google images find your images

Alec Jacobson

July 21, 2009

weblog/

I've been using a javascript turned perl turned ruby gallery script to make hosting images as easy and sleek as possible. But I've found that google (and of course if there are other search engines then those, too) has not indexed the images shown in my gallery. All other images on my site that are included on a static html page eventually show up. I don't want to give up my gallery script (hopefully I'll post that code soon). So, I drew up some quick bash code to find all the images on my site and throw them into a static page, which I then hide links to all over my site. Here's the bash code that can be run periodically (it's not necessary to do it all the time since search engines aren't caching the site all the time...but obviously more often is better). Here's my script, named make_all.sh:
#!/bin/bash
# Generate an html page with links to all images in this dir
# Author: Alec Jacobson (alecjacobson[strudel]gmail.com)
#
# To write links to all images in dir/ to index.html run:
# $ ./make_all.sh dir/ index.html 
#
echo "<html><body>" > $2
links=`find $1 -iregex ".*.jpe?g$" \
  | sed "s/\(^.*$\)/<a href=\"\1\" ><img alt=\'\[ideal query]\' src=\"\1\"\/><\/a>/"`
echo $links >> $2
echo "</body></html>" >> $2
Change ".*.jpe?g$" as you see fit (I'm only worrying about jpegs). Since I want my images to come when my name is searched I put my name in the alt field for [ideal query]. I also add a little text to the page to be sure it isn't ignored for lack of content. Next, since I don't intend for human users to see this page but I still want the crawlers to find it I hide links all over my site using:
<a href="[path to your static index of images.html]" style="text-decoration:none;">&nbsp;</a>
You could even get really carried away hiding it and move it off the visible pages using position:absolute; top:-1;. Here's my static page of all my images, and between these parenthesis is an example of a hidden link ( ). I will report back with whether this has worked successfully for me.