Sunday, March 7, 2010

Code that other people might use

Since I got the DSLR, one of my big practical complaints is the lack of digital zoom; of course, I'd prefer the equivalent optical zoom, but I'm not going for lenses that need their own tripods and cost more than a car... the complaint is simpler than that: I do all of my framing and composition in the camera, I don't modify pictures coming off the camera; maybe someday, but for now I actually find the "untouched digital negative" model appealing. (Also I spend enough extra time on sorting and captioning as it is, I don't *need* more work in my workflow, and my audience hasn't had specific complaints in any case...) This means that even at maximum (250mm) zoom, I'm getting useful pictures with huge excesses of whitespace (in the typesetting sense - sky, irrelevant shrubbery, etc.)

The normal approach would be to add a cropping step... but I'm using kphotoalbum, and it doesn't have one (it also buys into the "don't touch your originals" model, and I love it for tagging, so it's a good fit; it's just that it's purely for tagging/captioning/filing and doesn't have a slot for picture-modifying/deriving workflow extensions.)

I started sketching out the pieces involved, and when I got to the "UI" part, I realized I'd considered this before - that I wanted a feature like this in flickr itself. flickr already has a "notes" feature (drag out a rectangle, associate some text with it) and a rich and reasonably well documented API...

This brings us to my project of the last two days: auto_cropr looks at your recent pictures for ones with "cropr_me" tags on them (usefully, adding such a tag seems to make the picture newly recent.) Then it looks for a note (by the album owner only) with the text "cropr_me" (it would accept blank notes too, but flickr doesn't actually let you create those, and I want to match *some* string just to avoid stomping on other tags or generating lots of unintended clips - or for that matter, to allow a picture with a clip-note to have other notes too.) Given the note, it downloads the "Original", transforms the note into the appropriate coordinate space, uses PIL to clip out the rectangle, then uploads that back, with duplicate tags, map location, and date-taken... and then rewrites the original note to point to the clip (and points the caption back at the original picture.) Here's an example.

The tool is by no means complete - it's just reached the point where it works on my own live data, and solves the problem I started with. Things missing include

  • copying explicit permissions
  • copying "safety" level
  • putting EXIF/JFIF metadata/thumbnail in the cropped image
  • handling rotation (not hard, I just haven't had a real case where I needed it)
  • support for operating on someone else's album (mostly a matter of parameterizing the auth token/auth "frob" parts more than I've needed to - flickr's API is good for that)
  • coming up with a way for other people to use it - either as a packaged commandline tool, or a real "service" that you can sign up for on a web page.

Other than rotation, I don't need the rest of these for my use; I'd need to start asking around and see if anyone else actually wants the feature before setting up the rest (in theory I could use it as a chance to work through how to build flickr apps that other people can use - in practice, I don't actually have even a second app in mind, unless I go down the "back up all of your cloud services for you" path, and that's got a rather different structure.)

Not that I've told anyone about this blog, but I should start asking somewhere, so this will do: if this interests you, let me know (in comments here, or via the usual social networking paths.)

ps. It also needs a better name - it's not actually doing automatic cropping, in the sense of stripping excess "empty" space and applying rule-of-thirds heuristics or something like that, merely automated cropping.

No comments:

Post a Comment