From 24fbf46971e6ba93313634a825049728e928f8c0 Mon Sep 17 00:00:00 2001 From: kitazaki Date: Fri, 30 Aug 2019 18:31:54 +0900 Subject: [PATCH] Add files via upload --- led-badge-11x44.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/led-badge-11x44.py b/led-badge-11x44.py index 46389c9..f882072 100755 --- a/led-badge-11x44.py +++ b/led-badge-11x44.py @@ -328,13 +328,14 @@ def bitmap_img(file): for bit in range(8): bit_val = 0 x = 8*col+bit - pixel_color = im.getpixel( (x, row) ) - if isinstance(pixel_color, tuple): - monochrome_color = sum(pixel_color[:3]) / len(pixel_color[:3]) - elif isinstance(pixel_color, int): - monochrome_color = pixel_color - else: - sys.exit("%s: Unknown pixel format detected (%s)!" % (file, pixel_color)) + if x < im.width: + pixel_color = im.getpixel( (x, row) ) + if isinstance(pixel_color, tuple): + monochrome_color = sum(pixel_color[:3]) / len(pixel_color[:3]) + elif isinstance(pixel_color, int): + monochrome_color = pixel_color + else: + sys.exit("%s: Unknown pixel format detected (%s)!" % (file, pixel_color)) if x < im.width and monochrome_color > 127: bit_val = 1 << (7-bit) byte_val += bit_val