0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python Pillowによる連番画像の作成

Posted at

概要

 会議資料の右上によくある
image0.png
みたいものをまとめて作成します。
 作成した資料番号の画像を、PDFに貼り付けると会議資料の完成です。

コード

from PIL import Image, ImageDraw, ImageFont

# PCローカルのフォントへのパスと、フォントサイズ(20)を指定
font = ImageFont.truetype('C:/Windows/Fonts/meiryob.ttc', 20)

def drawing(number, label):
    x = 30 # 縦
    y = int(len(label)*10) + len(str(number)) + 90 # 横

    # RGB, 画像サイズ, 背景色を設定
    im = Image.new("RGB", (y, x), (256, 256, 256))
    draw = ImageDraw.Draw(im)
    text = label + str(number)

    # 描画位置、描画する文字(改行は\n)、文字色、フォントを指定
    draw.multiline_text((20, 0), text, fill=(26, 39, 146), font=font, anchor=None)
    
    # 枠線の幅色
    draw.rectangle([(0, 0), (y, x)], fill = None, outline="#000000", width = 3)
    # draw.rectangle([(0,0), (140,30)], fill = None, outline="#000000", width = 3)

    # ファイルに出力
    im.save("./" + label + str(number) + ".png")

# 個数と、接頭辞を指定
for i in range(12):
    drawing(i, "資料")
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?