Fixed x >= im.width bug.

Hand improved gfx/falafue_logo_44x11 font.
pull/1/head
Jürgen Weigert 5 years ago
parent bac0465209
commit 940c7e5e91
  1. BIN
      gfx/falafue_logo_44x11.png
  2. 25
      led-badge-11x44.py

Binary file not shown.

Before

Width:  |  Height:  |  Size: 368 B

After

Width:  |  Height:  |  Size: 364 B

@ -323,21 +323,22 @@ def bitmap_img(file):
buf = array('B') buf = array('B')
cols = int((im.width+7)/8) cols = int((im.width+7)/8)
for col in range(cols): for col in range(cols):
for row in range(11): for row in range(11): # [0..10]
byte_val = 0 byte_val = 0
for bit in range(8): for bit in range(8): # [0..7]
bit_val = 0 bit_val = 0
x = 8*col+bit x = 8*col+bit
pixel_color = im.getpixel( (x, row) ) if x < im.width:
if isinstance(pixel_color, tuple): pixel_color = im.getpixel( (x, row) )
monochrome_color = sum(pixel_color[:3]) / len(pixel_color[:3]) if isinstance(pixel_color, tuple):
elif isinstance(pixel_color, int): monochrome_color = sum(pixel_color[:3]) / len(pixel_color[:3])
monochrome_color = pixel_color elif isinstance(pixel_color, int):
else: monochrome_color = pixel_color
sys.exit("%s: Unknown pixel format detected (%s)!" % (file, pixel_color)) else:
if x < im.width and monochrome_color > 127: sys.exit("%s: Unknown pixel format detected (%s)!" % (file, pixel_color))
bit_val = 1 << (7-bit) if monochrome_color > 127:
byte_val += bit_val bit_val = 1 << (7-bit)
byte_val += bit_val
buf.append(byte_val) buf.append(byte_val)
im.close() im.close()
return (buf, cols) return (buf, cols)

Loading…
Cancel
Save