Skip to content

add support for jpg and png images #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions adafruit_portalbase/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import gc

import adafruit_imageload
import displayio

__version__ = "0.0.0+auto.0"
Expand Down Expand Up @@ -76,11 +77,18 @@ def set_background(self, file_or_color, position=None):

if not file_or_color:
return # we're done, no background desired
if isinstance(file_or_color, str): # its a filenme:
background = displayio.OnDiskBitmap(file_or_color)
if isinstance(file_or_color, str): # it's a filename:
file_lower = file_or_color.lower()
if file_lower.endswith(".bmp"):
background = displayio.OnDiskBitmap(file_or_color)
palette = background.pixel_shader
elif file_lower.endswith(".jpg") or file_lower.endswith(".jpeg") or file_lower.endswith(".png"):
background, palette = adafruit_imageload.load(file_or_color)
else:
raise ValueError(f"Image File type {file_or_color} not supported")
self._bg_sprite = displayio.TileGrid(
background,
pixel_shader=background.pixel_shader,
pixel_shader=palette,
x=position[0],
y=position[1],
)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ adafruit-circuitpython-miniqr
adafruit-circuitpython-requests
adafruit-circuitpython-fakerequests
adafruit-circuitpython-simpleio
adafruit-circuitpython-imageload
Loading