Skip to content

Instantly share code, notes, and snippets.

@tak-km
Created March 25, 2018 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tak-km/8e0e6fdb94d4dac4732c5d4ef32c2276 to your computer and use it in GitHub Desktop.
Save tak-km/8e0e6fdb94d4dac4732c5d4ef32c2276 to your computer and use it in GitHub Desktop.
#! /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