diff --git a/README.md b/README.md index a3b202f..50a15f5 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Python library for [Inky pHAT](https://shop.pimoroni.com/products/inky-phat), [I ### Inky Impression -[Inky Impression](https://shop.pimoroni.com/?q=inky+impression) is our line of glorious 7 colour eInk displays, available in [4"](https://shop.pimoroni.com/products/inky-impression-4) (640 x 400 pixel) [5.7"](https://shop.pimoroni.com/products/inky-impression-5-7) (600 x 448 pixel) and [7.3"](https://shop.pimoroni.com/products/inky-impression-7-3) (800 x 480 pixel) flavours. They're packed with strong colours and perfect for displaying striking graphics or lots of data. +[Inky Impression](https://shop.pimoroni.com/search?q=inky%20impression) is our line of glorious colour eInk displays, available in various sizes from the petite 4.0" up to the mighty 13.3". They're packed with strong colours and perfect for displaying striking graphics or lots of data. ## Installation diff --git a/examples/7color/hello_world.py b/examples/7color/hello_world.py new file mode 100644 index 0000000..1544e68 --- /dev/null +++ b/examples/7color/hello_world.py @@ -0,0 +1,25 @@ +# This basic example shows how to draw shapes and text on Inky Impression using PIL. + +from font_fredoka_one import FredokaOne +from PIL import Image, ImageDraw, ImageFont + +from inky.auto import auto + +inky_display = auto(ask_user=True, verbose=True) + +# Create new PIL image with a white background +image = Image.new("P", (inky_display.width, inky_display.height), inky_display.WHITE) +draw = ImageDraw.Draw(image) + +font = ImageFont.truetype(FredokaOne, 72) + +# draw some shapes +draw.rectangle((50, 50, 200, 200), fill=inky_display.YELLOW) # Rectangle +draw.ellipse((150, 150, 300, 300), fill=inky_display.RED) # Circle (ellipse) +draw.line((0, 0, 400, 400), fill=inky_display.BLUE, width=10) # Diagonal line + +# draw some text +draw.text((0, 0), "Hello, World!", inky_display.BLACK, font) + +inky_display.set_image(image) +inky_display.show() diff --git a/examples/spectra6/comics/README.md b/examples/spectra6/comics/README.md new file mode 100644 index 0000000..4f81a88 --- /dev/null +++ b/examples/spectra6/comics/README.md @@ -0,0 +1,33 @@ +# comic.py + +`comic.py` fetches and displays a random comic book cover from the Comic Vine API. + +- [comic.py](#comicpy) + - [About Comic Vine](#about-comic-vine) + - [Pre-requisites](#pre-requisites) + - [Usage](#usage) + - [Notes](#notes) + +You can find a more detailed run down of how to use this script in our Learn Guide: + +- [Learn: Displaying Comics on Inky Impression](https://learn.pimoroni.com/article/comics-on-inky-impression) + +## About 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. Check it out at https://comicvine.gamespot.com/ ! + +## Pre-requisites + +You'll need to have the Inky library installed and your virtual environment activated: `source ~/.virtualenvs/pimoroni/bin/activate` + +## Usage + +1. Get a Comic Vine API key: [https://comicvine.gamespot.com/api/](https://comicvine.gamespot.com/api/) +2. Edit the script to add your API key (`API_KEY` variable). +3. Run the script: `python comic.py` +4. The script will fetch a random comic cover and display it on your Inky Impression. + +## Notes + +- You can change which volumes/series are searched by adding or removing strings from the `SEARCH_QUERIES` variable - the default is 'Weird Science', which looks like a great read. +- Set `RANDOM_VOLUME = True` to select a random volume from the top 5 search results instead of choosing the first one. We found this varied things up when there were multiple volumes with the same title. \ No newline at end of file diff --git a/examples/spectra6/comics/comic.py b/examples/spectra6/comics/comic.py new file mode 100644 index 0000000..70abd2a --- /dev/null +++ b/examples/spectra6/comics/comic.py @@ -0,0 +1,97 @@ +""" +Python script to fetch a randomised comic cover from the Comic Vine API and show it on an Inky Impression display. +You will need to sign up for an API key at https://comicvine.gamespot.com/api/ to use this script. +Change the search query to the comic series you want to display! +""" + +import random +from io import BytesIO + +import requests +from PIL import Image + +from inky.auto import auto + +# Comic Vine API details +API_KEY = "API_KEY_GOES_HERE" +BASE_URL = "https://comicvine.gamespot.com/api/" +HEADERS = {"User-Agent": "Python Comic Vine Client"} + +# List of comic series to display, separated by commas. You can add more series to this list, or change the existing ones. +SEARCH_QUERIES = ["Weird Science"] +# Set to True to pick a random volume from the query results (this is helpful if the series is split into multiple volumes): +RANDOM_VOLUME = False + +# Inky Impression display setup +inky_display = auto() + + +def find_volume_id(api_key, query): + # Our first API call finds a list of volumes that match the search query, and then picks one + params = {"api_key": api_key, "format": "json", "query": query, "resources": "volume", "limit": 5} + response = requests.get(f"{BASE_URL}search/", headers=HEADERS, params=params) + response.raise_for_status() + data = response.json() + response.close() + results = data.get("results", []) + if results: + for idx, volume in enumerate(results, 1): + print(f"{idx}: {volume['name']} (ID: {volume['id']}, Start Year: {volume.get('start_year', 'N/A')})") + + if RANDOM_VOLUME is True: + # Pick a random volume from the search results + chosen = random.choice(results) + print(f"Randomly selected: {chosen['name']} (ID: {chosen['id']})") + else: + # Pick the first volume from the search results + chosen = results[0] + print("Picked first result!") + return chosen["id"] + else: + raise ValueError("No volumes found for the given query.") + + +def fetch_random_comic_image(api_key, series_id): + # Once we know the volume ID we can do a second API call to fetch a list of issues and pick a random cover image + params = {"api_key": api_key, "format": "json", "filter": f"volume:{series_id}", "limit": 100} + response = requests.get(f"{BASE_URL}issues/", headers=HEADERS, params=params) + response.raise_for_status() + data = response.json() + response.close() + results = data.get("results", []) + if results: + issue = random.choice(results) + # print a link to the issue page on Comic Vine + print(f"Random issue selected: ID: {issue['id']}") + print(f"Find out more: {issue['site_detail_url']}") + image_link = issue["image"]["original_url"] + return image_link + else: + raise ValueError("No comic issues found for the specified series.") + + +def display_image_on_inky(image_url): + # Display image on Inky Impression + response = requests.get(image_url) + response.raise_for_status() + image = Image.open(BytesIO(response.content)) + response.close() + + # Rotate the image if it is taller than it is wide + if image.height > image.width: + image = image.rotate(90, expand=True) + + image = image.resize(inky_display.resolution) + inky_display.set_image(image) + print("Updating Inky Impression!") + inky_display.show() + + +try: + # Pick a random search term from the list + search_query = random.choice(SEARCH_QUERIES) + volume_id = find_volume_id(API_KEY, search_query) + comic_image_url = fetch_random_comic_image(API_KEY, volume_id) + display_image_on_inky(comic_image_url) +except Exception as e: + print(f"Error: {e}") diff --git a/examples/spectra6/hello_world.py b/examples/spectra6/hello_world.py new file mode 100644 index 0000000..1544e68 --- /dev/null +++ b/examples/spectra6/hello_world.py @@ -0,0 +1,25 @@ +# This basic example shows how to draw shapes and text on Inky Impression using PIL. + +from font_fredoka_one import FredokaOne +from PIL import Image, ImageDraw, ImageFont + +from inky.auto import auto + +inky_display = auto(ask_user=True, verbose=True) + +# Create new PIL image with a white background +image = Image.new("P", (inky_display.width, inky_display.height), inky_display.WHITE) +draw = ImageDraw.Draw(image) + +font = ImageFont.truetype(FredokaOne, 72) + +# draw some shapes +draw.rectangle((50, 50, 200, 200), fill=inky_display.YELLOW) # Rectangle +draw.ellipse((150, 150, 300, 300), fill=inky_display.RED) # Circle (ellipse) +draw.line((0, 0, 400, 400), fill=inky_display.BLUE, width=10) # Diagonal line + +# draw some text +draw.text((0, 0), "Hello, World!", inky_display.BLACK, font) + +inky_display.set_image(image) +inky_display.show()