【发布时间】:2017-09-04 14:08:35
【问题描述】:
我在使用 Pillow 时遇到了一个小(我猜)错误。我正在尝试使用变量设置文本的颜色,但在尝试时得到 ValueError: unknown color specifier: '"232,43,123,255"'。 这是我的代码:
header = Image.open("A.png")
couleur_Ellipse = "rose"
draw = ImageDraw.Draw(header)
point = ( int(header.width * 0.780), int(header.height * 0.68))
header.paste(ellipse, point, ellipse)
colortext = '"232,43,123,255"'
pointtext1 = ( int(header.width * 0.845), int(header.height * 0.75))
pointtext2 = ( int(header.width * 0.798), int(header.height * 0.79))
draw.text(pointtext1, "this is some text", font=ImageFont.truetype("C:\Windows\Fonts\Arial.ttf", 14), fill=colortext)
draw.text(pointtext2, "some other text", font=ImageFont.truetype("C:\Windows\Fonts\\arialbd.ttf", 55), fill=colortext)
header.save('Images/header ' + couleur_Ellipse + '.png')
有什么见解吗?我不明白为什么它不起作用
【问题讨论】:
-
pillow.readthedocs.io/en/3.1.x/reference/ImageColor.html 似乎您需要提供颜色函数,而不仅仅是一串值。我还假设您使用的 PIL 版本等于或大于 1.1.4,以便您可以提供 alpha 值?尝试不使用 alpha:colortext = "rgb(232,43,123)"
-
有效!非常感谢。我不是母语人士,所以文档对我来说总是有点难以阅读。谢谢!