Created
July 15, 2019 23:42
-
-
Save sshh12/cfee187e45a83af6c4955ce6f7f98881 to your computer and use it in GitHub Desktop.
Convert an image into a json array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
im = Image.open('banner.png').convert('RGB') | |
width, height = im.size | |
col_start = -1 | |
for c in range(width): | |
content = False | |
for r in range(height): | |
color = im.getpixel((c, r)) | |
if color != (255, 255, 255): | |
content = True | |
break | |
if content: | |
col_start = c | |
break | |
for r in range(height): | |
row_data = [] | |
for c in range(col_start, width): | |
color = im.getpixel((c, r)) | |
if color == (255, 255, 255): | |
val = 0 | |
else: | |
val = 4 | |
row_data.append(val) | |
print(row_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment