The Drupal Image Module and How I Rewrote it

by ian

As many of the people who read this site know (which, according to Google analytics, is approximately 6), I recently spent 10 days in London. While there, I took a lot of pictures. I'm pretty sure I took close to 1500 and my mom took another 1000 or so. The better pictures are now posted here. Initially, I'd been using the Image module and its included Image Gallery and Image Import modules to manage the pictures on this site.

The Image module creates an image node type with a custom field for uploading images. The Gallery module associates taxonomy with Image nodes and creates some views for nicely displaying images.  Image Import imports images from a specified folder on the server.

This system seemed more than adequate at first, but I started running into problems when I wanted to add watermarks. It seems the generally accepted method for watermarking (or really doing any image modification) with Drupal is via the ImageCache module. With ImageCache, one creates a preset of all the things that should be done to an image. But then what? It took me a while to figure out that, without delving into PHP, ImageCache presets can really only be applied to CCK fields (well, ok, they can also be applied to colorbox popups, but that only helps so much). After further research, I found several blog posts in which people indicated that they create a custom node type with an ImageField field, then use views and their own taxonomies to create galleries instead of using the Image module and its associated modules. I was ok with doing that, but it presented several problems: no mass import and what to do with my current images.

Last Friday or Saturday, I started coding alternative Image, Image Gallery and Image Import modules. All three borrow heavily from the original versions but each has many functions that are complete rewrites. Image does little more than install a node type with an ImageField and several ImageCache presets. Gallery creates a taxonomy for galleries and provides views and Views plugins to display that taxonomy in a nice, (easily?) themable way. Unlike the original, Gallery explicitly depends on Views so there is no need for a fallback to php. Import works in pretty much the same way as the original: one uploads images to a specified folder and then visits a page to select images to import. When I was importing with the original, I ran into some memory issues if I tried to import too many at one time. That problem went away which I'm guessing is a result of how ImageField does its processing. In the future, I'm planning on adding an Import All button to the Import module that way one doesn't need to import, say, fifty at a time. I also want to create a module to transfer images from the original Image module and I'd like to create a module that can create multiple image nodes at once without needing server access (i.e. an AJAX or Flash based uploader).