开发者

python: reportlab, how to remove black borders from image

开发者 https://www.devze.com 2023-02-18 19:12 出处:网络
I am trying to generate a pdf file, using python reportlab, but is seems image is displayed with strange black border in pdf.

I am trying to generate a pdf file, using python reportlab, but is seems image is displayed with strange black border in pdf.

Here is the code:

# Standalone script to generate pdf lessons

from report开发者_如何学Clab.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()

The image I am trying to add is here

python: reportlab, how to remove black borders from image

Can somebody advice why the black line on the left have appeared, and how to fix it?


The problem isn't with a border, rather your chessboard has transparent pixels on the right and bottom sides, and reportlab isn't recognizing the alpha channel and is painting the transparent section as black:

python: reportlab, how to remove black borders from image

Using mask='auto' tells drawImage to use the alpha channel in your PNG, so the background shows through:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号