add image converter
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,23 @@
|
|||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
def generate_bitmap(input_path, output_path):
|
||||||
|
# 1. Resize to 90x90
|
||||||
|
img = Image.open(input_path).convert('1').resize((90, 90))
|
||||||
|
width, height = img.size
|
||||||
|
|
||||||
|
# Calculate bytes per row (90 pixels needs 12 bytes)
|
||||||
|
bytes_per_row = (width + 7) // 8
|
||||||
|
bitmap = bytearray(bytes_per_row * height) # 1080 bytes total
|
||||||
|
|
||||||
|
for y in range(height):
|
||||||
|
for x in range(width):
|
||||||
|
if img.getpixel((x, y)) == 0: # 0 is black
|
||||||
|
byte_idx = y * bytes_per_row + (x // 8)
|
||||||
|
bit_idx = 7 - (x % 8)
|
||||||
|
bitmap[byte_idx] |= (1 << bit_idx)
|
||||||
|
|
||||||
|
with open(output_path, "wb") as f:
|
||||||
|
f.write(bitmap)
|
||||||
|
print(f"Created {output_path} with size: {len(bitmap)} bytes")
|
||||||
|
|
||||||
|
generate_bitmap("logo.png", "./data/logo.bin")
|
||||||
Binary file not shown.
Reference in New Issue
Block a user