PIL 一秒切九图 朋友圈发图神器
注意图片像素返回值是(宽度,高度),pil填像素点坐标原点左上角。
判断像素点是否在圆方程中。
import numpy as np from PIL import Image file = input() im = Image.open(file) R,C = im.size newR = R//3 newC = C//3 picls = [] for i in range(9): picls.append(Image.new('RGB', (newR, newC),(255,255,255))) cnt = 0 for i in range(3): for j in range(3): for x in range(i * newC, (i + 1) * newC): for y in range(j*newR,(j+1)*newR): if 4*C*C*(y-R//2)*(y-R//2) + 4*R*R*(x - C//2)*(x - C//2) <= R*R*C*C: r, g, b = im.getpixel((y, x)) else : r, g, b = 255,255,255 picls[cnt].putpixel((y-(j*newR),x-i*newC),(r,g,b)) cnt+=1 for i in range(9): picls[i].save("".join(str(i))+".jpg")