Python Wand convert PDF to PNG disable transparent (alpha_channel)

前端 未结 5 1904
孤街浪徒
孤街浪徒 2020-11-29 03:23

I\'m trying to convert a PDF to PNG - this all works fine, however, the output image is still transparent even when I believe I have disabled it:

with Image(         


        
5条回答
  •  情歌与酒
    2020-11-29 03:38

    The other answer (compositing with a white image) works, but only on the last page, as does setting the alpha channel directly. The following works on wand 0.4.2:

    im = wand_image(filename='/tmp/foo.pdf', resolution=200)
    for i, page in enumerate(im.sequence):
        with wand_image(page) as page_image:
            page_image.alpha_channel = False
            page_image.save(filename='/tmp/foo.pdf.images/page-%s.png' % i)
    

    I think this is probably a bug in wand. It seems like setting the alpha channel for a PDF should affect all pages, but it doesn't.

提交回复
热议问题