Generating Pretty Instagram Quote Images in R

Here’s a fun little project I worked on over the weekend. This script can take a .tsv file of quotes/text and their sources, and output pretty Instagram-ready quote images with a splash of random colouring. For example:

I’d seen a few people getting onboard the quote-image train on Instagram as a fairly easy way of generating content for the site. And this intrigued me as generating social media content is definitely something I’ve, uh, struggled with since launching Parkour Clinic. But, considering I just self-published a 15,000 word paper (on top of the 6,500 word paper from last year) full of juicy parkour quotes, I figured this would be an ideal way for me to get my own content train finally moving.

The only trouble is, I kind of hate image editing these days? I find it really finicky, and I know what I’m like - I’ll create twenty images and then decide I don’t like the font, and have to create them all over again. So I decided to look into a way of creating them programmatically, and the magick package in R can do exactly that.

Initially I was creating the background colours by hand and just overlaying the text - not that hard to do with magick’s image annotate function. But, the fun came when I decided to try and also vary the colours of the background slice and text together in pure code, using magick::image draw along with some of R’s base graphics functions. These were fun to figure out because they felt like something older and less user-friendly than a lot of modern R package functionality, and at the end of it all, left me with a sense of understanding R better, which is always a great outcome to these little side projects.

I also totally spent ages figuring out and implementing my own word_wrap function, that was a bit rubbish, before accidentally discovering there was already one in base R with strwrap. Oh well. Good to know for the future!

The result is that, with ten minutes work copying and pasting choice excerpts from my papers into a single quotes.tsv file, I was able to quickly and easily generate nearly 40 quote images I can drip out on the Parkour Clinic Instagram over the coming months. Perfect. And if I decide to change some colours or a font, well, it takes about ten seconds to recreate them all. Absolute bliss.

If you’d like to generate your own quotes, you can download this project from GitHub!

📎 Tags:

📂 Recent posts in Blog: