circle_trim.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
# circle_trim.py
#
# Oct/02/2018
#
# --------------------------------------------------------------------
import sys
import math
from PIL import Image
# --------------------------------------------------------------------
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 = Image.open(file_in)
if img.mode != "RGB":
img = img.convert("RGB")
width, height = img.size
sys.stderr.write("%d\t%d\n" % (width,height))
#
xx_center = width / 2
yy_center = height / 2
rr_max = 90
#
for xx in range (width):
for yy in range (height):
delt_x = abs (xx_center - xx)
delt_y = abs (yy_center - yy)
arm = math.sqrt (delt_x * delt_x + delt_y * delt_y)
if (rr_max < arm):
img.putpixel((xx, yy), (255, 255, 255))
#
img.save(file_out)
#
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------
実行方法
./circle_trim.py in01.jpg out01.jpg