Python PIL加倍图像

时间:2018-09-23 02:43:58

标签: python python-3.x python-imaging-library

我正在尝试绘制2张图像,但出现此奇怪的错误。在大多数情况下,图像绘制都很好。

This is -或-enter image description here

这是两个通常的符号。但是,这是随机输出的东西。大多数情况下,此代码正常工作,但有时会这样做:

enter image description here

这是我的代码。第一个选择一个叠加图(不是两个)

   if 'Instant' in s.duration:
    durpic = Image.open('Dur-I.png')
elif 'round' in s.duration:
    durpic = Image.open('Dur-R.png')
    dnum = write_roman(int(re.search(r'\d+', s.duration).group()))
    draw = ImageDraw.Draw(durpic)
    w, h = draw.textsize(dnum)
    draw.text((0, 0), dnum, (0, 0, 0), font=font)
elif 'min' in s.duration:
    if 'Concentration' in s.duration:
        durpic = Image.open('Dur-CM.png')
    else:
        durpic = Image.open('Dur-M.png')
    dnum = write_roman(int(re.search(r'\d+', s.duration).group()))
    draw = ImageDraw.Draw(durpic)
    w, h = draw.textsize(dnum)
    draw.text((0, 0), dnum, (0, 0, 0), font=font)
elif 'hour' in s.duration:
    if 'Concentration' in s.duration:
        durpic = Image.open('Dur-CH.png')
    else:
        durpic = Image.open('Dur-H.png')
    dnum = write_roman(int(re.search(r'\d+', s.duration).group()))
    draw = ImageDraw.Draw(durpic)
    w, h = draw.textsize(dnum)
    draw.text((0, 0), dnum, (0, 0, 0), font=font)
elif 'day' in s.duration:
    if 'Concentration' in s.duration:
        durpic = Image.open('Dur-CD.png')
    else:
        durpic = Image.open('Dur-D.png')
    dnum = write_roman(int(re.search(r'\d+', s.duration).group()))
    draw = ImageDraw.Draw(durpic)
    w, h = draw.textsize(dnum)
    draw.text((0, 0), dnum, (0, 0, 0), font=font)
elif 'Until' in s.duration:
    durpic = Image.open('Dur-R.png')

将图像放在基础图像上

image_copy = scho.image
image_copy.paste(durpic, scho.point3, durpic)
imgpath = 'output/' + s.name + '.png'
image_copy.save(imgpath)

那么关于导致此错误的原因有什么建议?如果需要,我可以粘贴更多代码或更多输出示例。

0 个答案:

没有答案