Skip to content

Commit e1a8d84

Browse files
committed
Replace textsize function with textbbox
1 parent 9e77061 commit e1a8d84

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

examples/ssd1306_pillow_animate.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"SSD1306 ORGANIC LED DISPLAY. THIS IS AN OLD SCHOOL DEMO SCROLLER!!"
5252
+ "GREETZ TO: LADYADA & THE ADAFRUIT CREW, TRIXTER, FUTURE CREW, AND FARBRAUSCH"
5353
)
54-
maxwidth, unused = draw.textsize(text, font=font)
54+
bbox = draw.textbbox((0,0), text, font=font)
55+
maxwidth = bbox[2] - bbox[0]
5556

5657
# Set animation and sine wave parameters.
5758
amplitude = height / 4
@@ -73,15 +74,17 @@
7374
break
7475
# Calculate width but skip drawing if off the left side of screen.
7576
if x < -10:
76-
char_width, char_height = draw.textsize(c, font=font)
77+
bbox = draw.textbbox((0,0), c, font=font)
78+
char_width, char_height = bbox[2] - bbox[0], bbox[3] - bbox[1]
7779
x += char_width
7880
continue
7981
# Calculate offset from sine wave.
8082
y = offset + math.floor(amplitude * math.sin(x / float(width) * 2.0 * math.pi))
8183
# Draw text.
8284
draw.text((x, y), c, font=font, fill=255)
8385
# Increment x position based on chacacter width.
84-
char_width, char_height = draw.textsize(c, font=font)
86+
bbox = draw.textbbox((0,0), c, font=font)
87+
char_width, char_height = bbox[2] - bbox[0], bbox[3] - bbox[1]
8588
x += char_width
8689

8790
# Draw the image buffer.

0 commit comments

Comments
 (0)