こちらのプログラムを改造して、変換されら部分を透過にしました。
pillow で図形をトリム
入力データ
circle_transparent.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
# circle_transparent.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)
img = img.convert("RGBA")
pixdata = img.load()
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):
pixdata[xx, yy] = (255, 255, 255, 0)
#
img.save(file_out)
#
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------
実行方法
./circle_transparent.py in01.png out01.png