Displaying Comics on Inky Impression

Bold images with a limited colour palette look great on our Inky Impression colour E Ink® displays. We've been enjoying displaying old 1950s and 1960s comic book art - the art style and the printing methods available at the time mean that they're ideally suited for viewing on Impression.

This quick guide will show you how to display comic covers from Comic Vine on your Inky Impression, both manually and using the API. The files we used for 3D printing the bezel shown in these photos are linked to at the bottom of this guide.

What is Comic Vine?

Comic Vine is an awesome online database of comic book information. It has a free API that can be used to search and retrieve detailed information about comics, including cover images, issue details, and more. You can browse the site at the link below:

What you'll need

  • A Raspberry Pi with Inky Impression attached. The code below will work with any size of Impression: 4", 5.7", 7.3" or 13.3" and all display variants.

You'll need to have Inky Impression attached to your Pi and installed the inky library before following the steps below. Instructions how to do that can be found in our Getting Started guide:

We'll be assuming that you're connecting to your Pi using SSH but you can plug in a keyboard, mouse and display if you prefer.

Displaying a comic

First we'll need to find a cover to display (we enjoyed this one, but you do you). Right click the image and copy the URL. Then, fire up your SSH client (we're using Putty) so you can run commands in your Pi's terminal:

Once you're connected to your Pi, run the following command to download the image to your Pi, substituting a different image URL if you wish:

wget https://comicvine.gamespot.com/a/uploads/scale_large/0/229/163489-18944-112530-1-weird-science.jpg -O comic.jpg

🎩 Top hat top tip: You can right mouse click in Putty (and some other SSH clients) to paste information stored in your computer's clipboard.

Let's write a quick bit of Python code to display our newly downloaded image on Inky Impression. We need to:

  • import PIL (Python Image Library) for working with images
  • add a few lines of code to initialise our Inky display
  • use PIL to rotate and resize the image to fit the display. On our 7.3" Inky stretching the image vertically slightly works pretty well, but you could use PIL to crop the image instead if you want to avoid distortion.
from PIL import Image

from inky.auto import auto

inky_display = auto()

image = Image.open("comic.jpg")
image = image.rotate(90, expand=True)
image = image.resize(inky_display.resolution)

inky_display.set_image(image, saturation=0.5)
inky_display.show()

You can type python on your Pi to open up a new Python prompt and then copy and paste the code, or you could do sudo nano test.py to create a new file on your Pi, and copy and paste the code there (it's Ctrl-X, Y and enter to save your changes once you're done). Once it's saved, you can run the script with python test.py.

ModuleNotFoundError: No module named 'inky'

If you get an error that looks like this when you try and run your code, double check that you have your virtual environment active - there should be a (pimoroni) before your terminal prompt.

You can activate it with:

source ~/.virtualenvs/pimoroni/bin/activate

Here's the code above running on a 7 colour 7.3" Impression, and a dinky 7 colour 4" Impression.

Displaying a comic using the API

But wouldn't it be cooler if your Raspberry Pi could pick and download a comic for you, without you having to search for and download it yourself? Luckily this is straightforward, as the nice people behind have Comic Vine have provided a free API that we can use. APIs are interfaces that allow different computers to talk to each other, which means it's possible for our Raspberry Pi to use the Comic Vine database by sending it HTTP commands (aka requests).

An extended version of our comic example which downloads a random comic from the Comic Vine API can be found at the link below:

We've added some additional code to handle our API requests, and split it up into three Python functions to keep things a bit more organised. Here's what the functions do:

  • To search for all comics that belong to a series (Comic Vine calls this a volume), we first need to find out its ID number, which is a five or six digit number. The find_volume_id function performs our first API request, where we supply a search string in the same way as we would if we did a search on the website. It returns the top five results, and picks the first one.
  • The fetch_random_comic_image function contains our second API request. Now that we have a volume ID we can do a search on that to return a list of issues (and, most importantly, the URLs for their associated cover images), and then pick one randomly.
  • Our third function downloads the image from the URL and displays it on Inky Impression.

Adding your API key

To run this code yourself, you will need to sign up for a Comic Vine account at the link below:

Once you've signed up and logged in to your account, you'll see your API key in the blue box at the top of this page. It's a long number so we'd suggest copying it to the clipboard.

In your SSH terminal, navigate to the examples directory on your Pi:

cd ~/Pimoroni/inky/examples/spectra6/comics

Then open up comic.py in a text editor:

sudo nano comic.py

Edit the file to replace API_KEY_GOES_HERE with your own API key.

When you're done editing, it's 'Ctrl-X', then 'Y', then enter to save your changes.

Now you can run the example with python comic.py. Make sure to activate your virtual environment first, if you're using a different login session to last time.

Using a different search query

Perhaps you would like to search for your own favourite comic book series, or pick from a pool of a few different ones? Just open up the code in nano again, and edit the SEARCH_QUERIES list to add (or remove) search string/s. Your list of series should be seperated by commas and look something like this when you're done.

SEARCH_QUERIES = ["Weird Science", "Weird Fantasy", "Weird Science-Fantasy", "Piracy", "Tales of The Unexpected"]

Searching multiple volumes

Sometimes comic series span multiple volumes from different time periods. By default the script will pick the first matching result, but if you'd prefer to pick from (up to five) matching volumes you can set RANDOM VOLUME = True to mix things up a bit.

Making your script run on a timer

This script only updates the image once, but if you wanted to get it to run periodically to update your artwork that's possible using a handy command-line tool called cron.

Open up the crontab file on your Pi by running the following command:

crontab -e

If it's the first time you're setting up a crontab, you'll need to select a text editor - press 1 and enter to open up nano. At the very bottom of your crontab file, add the following line. Make sure you replace USER with the name of the user account that you use to log into Raspberry Pi OS:

*/60 * * * * /home/USER/.virtualenvs/pimoroni/bin/python ~/Pimoroni/inky/examples/spectra6/comics/comic.py

That will run and update the image every 60 minutes, although you can change that number to a smaller or larger number depending on how frequently you'd like it to update. Bear in mind that the Comic Vine API is rate limited to 200 requests an hour, and it is polite to avoid overloading free APIs. It is also smart to avoid overly-frequent refreshes, to ensure the longevity of your E Ink display.

Adding a 3D printed frame

To make our Inky Impression look a bit more like a picture frame, we 3D printed a simple frame to make the bezel the same distance around the screen on all sides. If you'd like to do the same, you can find our 3D printing files at the link below:

We used M2 3mm bolts to fix it in place. The holes in the frame aren't threaded, but PLA is soft enough for the bolt threads to grab in place. This method might not hold up to multiple unscrewings though.

Once the bezel was attached, we used a Folding Tablet Stand to prop up our bezelled Inky.

Next steps

Hopefully this article has provided you with some inspiration for how you can incorporate online APIs into your own projects. If you give our script a try then do drop us a line on Bluesky, Instagram or our forums - we'd love to know what comics you've enjoyed looking at!

That's all folks!

Search above to find more great tutorials and guides.

Plasma 2040

Swathe everything in rainbows with this all-in-one, USB-C powered controller for WS2812/Neopixel and APA102/Dotstar addressable LED strip.