以下の「鬱」の中、どれかが「欝」だよ、さがしてみよう。
ヒント:この画像は50x50文字。コードが読めれば見当がつくよ。
以下のコードで書きました
from PIL import Image, ImageDraw, ImageFont
import numpy as np
size = 50 # 画像サイズ
ofs_y = 55.0 / 256 # オフセット(フォントごとに異なる)
font = ImageFont.truetype('Koruri-Bold.ttf', size)
img = Image.new('1', (size, size), color='white')
draw = ImageDraw.Draw(img)
draw.text((0, -ofs_y * size), '鬱', font=font, fill='black')
data = np.array(img)
i = 0
for stride in data:
for bit in stride:
i += 1
print("欝" if i == 1467 else " " if bit else "鬱", end= "")
print("")