LoginSignup
1
4

More than 5 years have passed since last update.

Pythonで、「漢字一字」のJpg画像を連続で作っていく

Posted at

プログラミングで、たくさんの漢字画像ファイルを書き出す方法です

※スクラッチの、漢字当てゲームのために、作りました
https://scratch.mit.edu/projects/280853889/
リンク

OUTIMG.py
#coding: utf-8

from PIL import Image, ImageDraw, ImageFont

font = ImageFont.truetype('/Library/Fonts/ヒラギノ丸ゴ ProN W4.ttc', 256)

with open('./kanji6.txt', 'r') as f:
    for s_line in f:
        s_line = s_line.replace('\n', '')
        s_line = s_line.replace('\r', '')

        im = Image.new("RGB", (256, 256), (255, 255, 255))
        draw = ImageDraw.Draw(im)
        draw.multiline_text((0, 0), unicode(s_line, 'utf-8'), fill=(0, 0, 0), font=font)
        im.save('./' + s_line + '.jpg', quality=95)
f.close()
kanji6.txt
異
遺
域
宇
映
延
沿
我
灰

漢字の画像ファイルができます

異.jpg

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4