Thumbnails by node id in Drupal


My problem: I’d like to be able to automatically construct a URL along the lines of http://www.mydrupalsite.com/images/thumbs/node/1.jpg and get back a JPEG image that represents that node. Most of my nodes have a field_pictures imagefield that takes multiple images, and they also use imagecache to generate thumbnails. I just want to bridge the gap between node and primary photo - the first photo in the list is fine as the primary photo, I just would like to be able to load a thumbnail image for a node without knowing anything else about it. This probably isn’t an issue for a pure Drupal installation, but in my case, I don’t want to load a node JSON array over the network to the iPhone, have the iPhone parse out the name first picture (if it exists), and then construct a URL to the thumbnail.

I’ve searched through Drupal.org for a module that already did this, or perhaps another solution, and there isn’t one. I know I don’t need to replicate imagecache’s functionality - I’d like to build on top of imagecache actually, and use imagecache to generate the thumbnails.

My thought is to create a new module that hooks onto a custom URL, and then when it receives a request for a thumbnail from say, node 1, returns either the thumbnail from imagecache, or a default/blank 64x64 JPEG. The way the module would work, it would load the node and take a look at the first image in field_pictures. If there is no image, return the default.jpg. If there is an image in the cache, serve up the image from the cache. If there is no image in the cache, use imagecache to create one, and then serve it.

Next steps are to look into the imagecache module to see what I can hook into or take advantage of for functionality.

This will make displaying thumbnails for each node in my iPhone app much easier than trying to create custom views for each set of node references in my application and maintaining that.