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 で画像に文字を挿入