【问题标题】:PIL ImageDraw text color changes to bluePIL ImageDraw 文本颜色变为蓝色
【发布时间】:2020-05-25 09:23:38
【问题描述】:

我正在编写一个程序来为我自己的“反人类卡片”创建一些卡片。 这是我的代码:

from PIL import Image, ImageDraw, ImageFont
import re

arialbold = ImageFont.truetype("arialbd.ttf",size=100)

while(True):

    testimg = Image.open("white.png")

    intext = input() + " "
    if(intext == " "):
        break

    inlist = list(intext)
    pattern = " "
    su = 0
    last = 0
    lastlen = 0

    for match in re.finditer(pattern,intext):
        su = su + (match.start() - last)
        print(su)
        if(su > 12):
            inlist[last] = '\n'
            su = lastlen
        lastlen = (match.start() - last)
        last = match.start()

    out = ''.join(inlist)

    tempimg = ImageDraw.Draw(testimg)
    tempimg.text((100,100),out ,fill= "#000000", font=arialbold)

    nameOfSave = re.sub('\W' ,'',intext[0:30])

    testimg.save(nameOfSave + ".png")

我想要做的只是在卡片上添加一个黑色分机(或稍后在黑色背景上添加一个白色文本),而不更改除文本颜色之外的任何颜色。

但是我的输出图像一直是蓝色的,我不明白为什么。

我试图改变 填充= 255 填充= (255,255,255) 但它没有帮助

提前感谢您的帮助!

【问题讨论】:

标签: python image-processing python-imaging-library


【解决方案1】:

testimg = Image.open("white.png").convert('RGB') 帮助并做到了!

感谢马克·塞切尔

我还是很好奇,为什么它变成了蓝色..

【讨论】:

    猜你喜欢
    • 2022-12-24
    • 2013-02-08
    • 2021-08-18
    • 2019-01-02
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    相关资源
    最近更新 更多