Serving images for Twitter
by Mark Meyer
2009 was the year that we all learned to whittle our thoughts down to 140 characters. We learned that three periods (...) is three characters while a true ellipsis (…) does the same job for a third the cost. You can save yourself 1.4% of a tweet with that trick alone and help the cause of typography everywhere. Twitter, of course, has been around since 2006 and hit the mainstream in 2008 when presidential candidates learned the art of the 140-character stump tweet, but it wasn't until last year that photographers discovered the service in earnest.
Twitter now has a vibrant photography community, but the nature of Twitter does not lend itself to photography without some help. You can't post an image directly into a tweet and URLs tend to be too long, consuming valuable space. To address these problems a small cottage industry has emerged to shorten URLs and post photos. Service like bit.ly will trim your URLs and websites like yfrog.com and twitpic.com offer small image hosting. Although the services are free they don't come without a cost. To begin with, you are at the mercy of their terms of service which they can change at their pleasure. Also, context is very important when showing your work and the context offered by these services is dreadful. Your work is competing with cheap (sometimes flashing) advertising, it gets downsized and compressed in ways beyond your control, and you are sending traffic to a third party website whose branding offers you nothing. Why should we as photography professionals chose to show any of our work, even snapshots like this? Why, when these services are not providing anything that is difficult to do yourself?
Reasserting control over the way my work is presented in social media was one of my projects over the holidays. When I post a link, I want to control where that link goes and have control over the analytic information that is captured. When I post a photo, I want to expose the viewer to my own branding and have links encouraging viewers to explore more of my website. It turned out to be very easy.
A quick technical overview
I bought a nice, compact domain name, phtm.us, since www.photo-mark.com is interminable by twitter standards. The server running photo-mark.com is already running on top of Django which is a database-backed framework for serving websites. Creating a URL shortener involves making a simple database table which includes the URL, a numeric ID (the primary key), and whatever other metadata I want to capture about the link. We now have everything we need to map a simple number (the ID) to a link. Since base 10 numbers aren't as compact as they could be I use a base 36 representation of the ID in the URL. (The number 10,000 for instance looks like 255S in base 36). So now when a request for a URL such as http://phtm.us/2 hits the server it looks up the record corresponding to ID 2 finds the original URL and sends your browser an HTTP 301 MOVED PERMANENTLY response with the original URL. This requires all of three lines in a Django view:
id = int(base36ID, 36)
resource = get_object_or_404(Resource, id=id)
return HttpResponsePermanentRedirect(resource.url)
Give it a try: http://phtm.us/2
Since I already have a system in place for storing images for the galleries, it's a simple matter to piggyback the gallery database onto the URL shortened to serve a special gallery of images I want to share though social media channels. I want to keep these separate from the main galleries since they are not edited for the same purpose, but I want to retain control of the look and feel of the experience. I set up the URL dispatcher to know the difference between a shortened URL with a link and one with an image and to serve the appropriate page.
For example: http://phtm.us/r
Now I have a simple service that doesn't send my traffic over to third parties, allows me to control how my work is seen, and gives me the option of adding features when I want them. For instance, a handy feature I just implemented for myself is a mail drop where I can email photos from my phone and they will appear on the mobile gallery instantly.