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 3 years have passed since last update.

pillow で画像に図形を挿入

Posted at

入力画像
fujisan01.jpg

出力画像
out01.jpg

draw_img_rect.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#	draw_img_rect.py
#
#						Feb/12/2021
#
# ------------------------------------------------------------------
import sys

import PIL.Image
import PIL.ImageDraw

# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
file_in = sys.argv[1]
file_out = sys.argv[2]
sys.stderr.write(file_in + "\n")
sys.stderr.write(file_out + "\n")
#
img_base = PIL.Image.open(file_in)
#

draw = PIL.ImageDraw.Draw(img_base)
xx = 50
yy = 50
delt_x = 100
delt_y = 100
draw.rectangle((xx,yy,xx + delt_x,yy + delt_y),fill=None,outline=(255,0,0),width=1)
xx = 200
draw.rectangle((xx,yy,xx + delt_x,yy + delt_y),fill=None,outline=(255,255,0),width=5)
xx = 350
draw.rectangle((xx,yy,xx + delt_x,yy + delt_y),fill=None,outline=(0,0,255),width=9)

xx=50
yy=200
draw.ellipse((xx, yy, xx+100, yy+100), fill=None, outline=(255,0,0),width=1)
xx=200
draw.ellipse((xx, yy, xx+100, yy+100), fill=None, outline=(255,255,0),width=5)
xx=350
draw.ellipse((xx, yy, xx+100, yy+100), fill=None, outline=(0,0,255),width=9)

img_base.show()

img_base.save(file_out)
sys.stderr.write("*** 終了 ***\n")
# ------------------------------------------------------------------

実行方法

./draw_img_rect.py fujisan01.jpg out01.jpg

関連ページ
pillow で画像に文字を挿入

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?