画像処理ライブラリPillow-Colabでの図形描画実行例
ナビゲーションに移動
検索に移動
実行例を示します。
from PIL import Image, ImageDraw # 画布を定義し、作成する。 canvas_width = 1000 canvas_height = 750 canvas = Image.new('RGB', (canvas_width, canvas_height), (255, 255, 255)) # 枠線を描き、図形を描く。 draw = ImageDraw.Draw(canvas) draw.line(((0,0),(999,0),(999,749),(0,749),(0,0)),fill="black") draw.ellipse((100,100,200,200),fill=(0,0,255)) draw.rectangle([200,100,350,200], fill="pink", outline="red", width=5) draw.polygon([(400,100),(500,100),(450,200)], fill="yellow", outline="green", width=5) draw.regular_polygon(((300,300),100), 5, rotation=0, fill="orange") canvas
この他にも色々試して、追加してください。