Skip to content

Instantly share code, notes, and snippets.

@skywodd
Created July 24, 2017 19:37
Show Gist options
  • Save skywodd/00a6a7efc0aad1ce7442256501f487cd to your computer and use it in GitHub Desktop.
Save skywodd/00a6a7efc0aad1ce7442256501f487cd to your computer and use it in GitHub Desktop.
Search for unicode crap
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