Skip to content

Added animated gif example #18

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
Dec 6, 2019
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
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This driver supports the following hardware:

* `Adafruit 16x9 Charlieplexed PWM LED Matrix Driver - IS31FL3731 <https://www.adafruit.com/product/2946>`_
* `Adafruit 15x7 CharliePlex LED Matrix Display FeatherWings <https://www.adafruit.com/product/2965>`_
* `Adafruit 16x8 CharliePlex LED Matrix Bonnets <https://www.adafruit.com/product/4127>`_

Dependencies
=============
Expand Down
47 changes: 47 additions & 0 deletions examples/is31fl3731_pillow_animated_gif.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import sys
import board
from PIL import Image
import adafruit_is31fl3731

i2c = board.I2C()

# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.Matrix(i2c)
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
display = adafruit_is31fl3731.CharlieBonnet(i2c)
display.fill(0)

# Open the gif
image = Image.open(sys.argv[1])

# Make sure it's animated
if not image.is_animated:
print("Specified image is not animated")
sys.exit()

# Get the autoplay information from the gif
delay = image.info['duration']
loops = image.info['loop']

# Adjust loop count (0 is forever)
if loops > 0:
loops += 1

# IS31FL3731 only supports 0-7
if loops > 7:
loops = 7

# Get the frame count (maximum 8 frames)
frame_count = image.n_frames
if frame_count > 8:
frame_count = 8

# Load each frame of the gif onto the Matrix
for frame in range(frame_count):
image.seek(frame)
frame_image = Image.new('L', (display.width, display.height))
frame_image.paste(image.convert("L"), (display.width // 2 - image.width // 2,
display.height // 2 - image.height // 2))
display.image(frame_image, frame=frame)

display.autoplay(delay=delay, loops=loops)