用 PIL 画圆(旧的不行)
Draw circle with PIL (Old ones doesn't works)
我想用 PIL 画一个圆,但是我得到了一个属性错误。
当前代码用于方形。
绘制部分代码:
youtube = Image.open(f"cache/thumb{videoid}.png")
image1 = changeImageSize(1280, 720, youtube)
image2 = image1.convert("RGBA")
background = image2.filter(filter=ImageFilter.BoxBlur(30))
enhancer = ImageEnhance.Brightness(background)
background = enhancer.enhance(0.6)
Xcenter = youtube.width / 2
Ycenter = youtube.height / 2
x1 = Xcenter - 250
y1 = Ycenter - 250
x2 = Xcenter + 250
y2 = Ycenter + 250
logo = youtube.crop((x1, y1, x2, y2))
logo.thumbnail((520, 520), Image.ANTIALIAS)
logo = ImageOps.expand(logo, border=15, fill="pink")
background.paste(logo, (50, 100))
draw = ImageDraw.Draw(background)
我的全部代码:
您可以使用 ImageDraw.arc()
或 ImageDraw.ellipse
。
from PIL import Image, ImageDraw
# Image size
W, H = 100, 100
# Bounding box points
X0 = int(W / 4)
X1 = int(X0 * 3)
Y0 = int(H / 4)
Y1 = int(X0 * 3)
# Bounding box
bbox = [X0, Y0, X1, Y1]
# Set up
im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im)
# Draw a circle
draw.arc(bbox, 0, 360)
# Show the image
im.show()
或:
# Draw a circle
draw.ellipse(bbox)
我想用 PIL 画一个圆,但是我得到了一个属性错误。
当前代码用于方形。
绘制部分代码:
youtube = Image.open(f"cache/thumb{videoid}.png")
image1 = changeImageSize(1280, 720, youtube)
image2 = image1.convert("RGBA")
background = image2.filter(filter=ImageFilter.BoxBlur(30))
enhancer = ImageEnhance.Brightness(background)
background = enhancer.enhance(0.6)
Xcenter = youtube.width / 2
Ycenter = youtube.height / 2
x1 = Xcenter - 250
y1 = Ycenter - 250
x2 = Xcenter + 250
y2 = Ycenter + 250
logo = youtube.crop((x1, y1, x2, y2))
logo.thumbnail((520, 520), Image.ANTIALIAS)
logo = ImageOps.expand(logo, border=15, fill="pink")
background.paste(logo, (50, 100))
draw = ImageDraw.Draw(background)
我的全部代码:
您可以使用 ImageDraw.arc()
或 ImageDraw.ellipse
。
from PIL import Image, ImageDraw
# Image size
W, H = 100, 100
# Bounding box points
X0 = int(W / 4)
X1 = int(X0 * 3)
Y0 = int(H / 4)
Y1 = int(X0 * 3)
# Bounding box
bbox = [X0, Y0, X1, Y1]
# Set up
im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im)
# Draw a circle
draw.arc(bbox, 0, 360)
# Show the image
im.show()
或:
# Draw a circle
draw.ellipse(bbox)