Skip to content

Commit 03acb80

Browse files
authored
Merge pull request #18 from makermelissa/master
Added animated gif example
2 parents 4d989cd + 41d8dfb commit 03acb80

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This driver supports the following hardware:
1919

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

2324
Dependencies
2425
=============
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Example to extract the frames and other parameters from an animated gif
3+
and then run the animation on the display.
4+
5+
Usage:
6+
python3 is31fl3731_pillow_animated_gif.py animated.gif
7+
8+
This example is for use on (Linux) computers that are using CPython with
9+
Adafruit Blinka to support CircuitPython libraries. CircuitPython does
10+
not support PIL/pillow (python imaging library)!
11+
12+
Author(s): Melissa LeBlanc-Williams for Adafruit Industries
13+
"""
14+
15+
import sys
16+
import board
17+
from PIL import Image
18+
import adafruit_is31fl3731
19+
20+
i2c = board.I2C()
21+
22+
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
23+
#display = adafruit_is31fl3731.Matrix(i2c)
24+
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
25+
display = adafruit_is31fl3731.CharlieBonnet(i2c)
26+
display.fill(0)
27+
28+
# Open the gif
29+
if len(sys.argv) < 2:
30+
print("No image file specified")
31+
print("Usage: python3 is31fl3731_pillow_animated_gif.py animated.gif")
32+
sys.exit()
33+
34+
image = Image.open(sys.argv[1])
35+
36+
# Make sure it's animated
37+
if not image.is_animated:
38+
print("Specified image is not animated")
39+
sys.exit()
40+
41+
# Get the autoplay information from the gif
42+
delay = image.info['duration']
43+
loops = image.info['loop']
44+
45+
# Adjust loop count (0 is forever)
46+
if loops > 0:
47+
loops += 1
48+
49+
# IS31FL3731 only supports 0-7
50+
if loops > 7:
51+
loops = 7
52+
53+
# Get the frame count (maximum 8 frames)
54+
frame_count = image.n_frames
55+
if frame_count > 8:
56+
frame_count = 8
57+
58+
# Load each frame of the gif onto the Matrix
59+
for frame in range(frame_count):
60+
image.seek(frame)
61+
frame_image = Image.new('L', (display.width, display.height))
62+
frame_image.paste(image.convert("L"), (display.width // 2 - image.width // 2,
63+
display.height // 2 - image.height // 2))
64+
display.image(frame_image, frame=frame)
65+
66+
display.autoplay(delay=delay, loops=loops)

examples/is31fl3731_pillow_numbers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Example to utilize the Python Imaging Library (Pillow) and draw bitmapped text
33
to 8 frames and then run autoplay on those frames.
44
5+
This example is for use on (Linux) computers that are using CPython with
6+
Adafruit Blinka to support CircuitPython libraries. CircuitPython does
7+
not support PIL/pillow (python imaging library)!
8+
59
Author(s): Melissa LeBlanc-Williams for Adafruit Industries
610
"""
711

0 commit comments

Comments
 (0)