MagTag Online Image

Posted on March 15, 2023

Here is a bit of code that pulls a random image from the internet and displays it on a MagTag screen.

import board
import displayio
import adafruit_imageload
import adafruit_requests as requests
import adafruit_magtag.magtag as magtag
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
from adafruit_imageload import dither

# Set up the MagTag display and buttons
magtag = magtag.MagTag()

# Get the image from
image_url = ""
response = requests.get(image_url)
image_file = response.content
image, palette = adafruit_imageload.load(image_file, bitmap=displayio.Bitmap, palette=displayio.Palette)

# Dither the image
dither.dither_bitmask(image, bitmap=displayio.Bitmap)

# Create a new display group and show the image on the screen
group = displayio.Group()
tile_grid = displayio.TileGrid(image, pixel_shader=palette)

# Wait for button press to exit
while not magtag.peripherals.button_a:

Comments are closed.