Skip to content

Commit

Permalink
badge.py: add png support
Browse files Browse the repository at this point in the history
  • Loading branch information
helgibbons committed Jun 21, 2024
1 parent 9e67d95 commit 21e27e8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions badger_os/examples/badge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import badger2040
import jpegdec
import pngdec


# Global Constants
Expand Down Expand Up @@ -56,9 +57,14 @@ def draw_badge():
display.set_pen(0)
display.clear()

# Draw badge image
jpeg.open_file(badge_image)
jpeg.decode(WIDTH - IMAGE_WIDTH, 0)
if badge_image.endswith('.png' or '.PNG' or '.Png'):
# Draw badge image
png.open_file(badge_image)
png.decode(WIDTH - IMAGE_WIDTH, 0)
else:
# Draw badge image
jpeg.open_file(badge_image)
jpeg.decode(WIDTH - IMAGE_WIDTH, 0)

# Draw a border around the image
display.set_pen(0)
Expand Down Expand Up @@ -123,6 +129,7 @@ def draw_badge():
display.set_thickness(2)

jpeg = jpegdec.JPEG(display.display)
png = pngdec.PNG(display.display)

# Open the badge file
try:
Expand Down

0 comments on commit 21e27e8

Please sign in to comment.