python:reportlab,如何从图像中删除黑色边框

时间:2011-03-20 18:36:59

标签: python reportlab

我正在尝试使用python reportlab生成一个pdf文件,但似乎图像在pdf中以奇怪的黑色边框显示。

以下是代码:

# Standalone script to generate pdf lessons

from reportlab.pdfgen import canvas
def hello(c):
    c.drawImage("./media/files/1.png", 0, 600, 350, 350)


c = canvas.Canvas("hello.pdf")
hello(c)
c.showPage()
c.save()

我要添加的图片是enter image description here

有人可以建议为什么左边的黑线出现了,以及如何修复它?

1 个答案:

答案 0 :(得分:2)

问题不在于边框,而是您的棋盘在右侧和底侧都有透明像素,而reportlab无法识别Alpha通道并将透明部分绘制为黑色:

enter image description here

使用mask='auto'告诉drawImage在PNG中使用alpha通道,因此背景显示:

c.drawImage("./media/files/1.png", 0, 600, 350, 350, mask='auto')