Created
March 25, 2018 14:32
-
-
Save tak-km/8e0e6fdb94d4dac4732c5d4ef32c2276 to your computer and use it in GitHub Desktop.
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
#! /usr/bin/env python | |
# coding: utf-8 | |
# coding=utf-8 | |
# -*- coding: utf-8 -*- | |
# vim: fileencoding=utf-8 | |
import sys | |
from PIL import ImageFont | |
from PIL import Image | |
from PIL import ImageDraw | |
import io | |
import subprocess | |
buf = io.BytesIO() | |
fontFile = 'KouzanGyoushoOTF.otf' | |
font = ImageFont.truetype(fontFile, 64, encoding='utf-8') | |
text = '謹賀新年' | |
w, h = font.getsize(text) | |
img = Image.new('RGB', (w, h), (255,255,255)) | |
draw = ImageDraw.Draw(img) | |
draw.text((0, 0), text, fill=(0,0,0), font=font) | |
img.save(buf, 'PNG') | |
# print out | |
p = subprocess.Popen('lpr', stdin=subprocess.PIPE) | |
p.communicate(buf.getvalue()) | |
p.stdin.close() | |
buf.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment