New square backgrounds for @pomological

I’m happy to say I’ve fixed the most frequent complaint I’ve gotten about @pomological: the images, while great, are overwhelmingly in the portrait orientation, making the preview images on many Twitter clients—and especially Twitter.com—kind of lousy.

No more! Beautiful squares on a color hand-picked to match most of the painting backdrops.

To address this, I had to learn a little about pillow, the leading Python image library. Now, when the bot downloads a random image from the watercolors, it draws a new neutral-colored box that’s a little longer than the painting’s longest side, and pastes the thing in the center of that.

The hardest part was ensuring the resulting image was in a format that Twitter can understand—especially because this is one of the handful of things that changed in between Python 2 and 3. But I persevered, and read a lot of documentation, and now it’s live.

Published by Parker Higgins

I'm the Director of Special Projects at the Freedom of the Press Foundation, and previously led copyright activism at the Electronic Frontier Foundation. I live and work in Brooklyn, New York. more »

Join the Conversation

2 Comments

  1. You can use Pillow to find the most frequent color in an image like so:


    i = Image.open('foo.jpg')
    h = i.histogram()
    r, g, b = h[:256], h[256:512], h[512:]
    most_frequent_color = (r.index(max(r)), g.index(max(g)), b.index(max(b)))

    Sacrificing consistency for maybe better fit?

Leave a comment

Your email address will not be published. Required fields are marked *