Created
July 24, 2017 19:37
-
-
Save skywodd/00a6a7efc0aad1ce7442256501f487cd to your computer and use it in GitHub Desktop.
Search for unicode crap
This file contains 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 collections import defaultdict | |
from PIL import ( | |
Image, | |
ImageDraw, | |
ImageFont | |
) | |
img = Image.new('1', (8, 16)) | |
font = ImageFont.truetype('arial.ttf', 10) | |
draw = ImageDraw.Draw(img) | |
forward_lut = {} | |
reverse_lut = defaultdict(list) | |
for i in range(32, 0xFFFF): | |
c = chr(i) | |
draw.rectangle((0, 0, 8, 16), fill=(255, )) | |
draw.text((0, 0), c, font=font, fill=(0, )) | |
pixels = map(lambda x: str(x & 1), img.getdata()) | |
footprint = int(''.join(pixels), 2) | |
reverse_lut[footprint].append(c) | |
forward_lut[c] = footprint |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment