This is a direct port by @deerful of Twitter's @thetinygallery
Can't promise it'll work in your, or any, client, & won't be debugging, sorry.