Python Wand convert PDF to PNG disable transparent (alpha_channel)

前端 未结 5 1903
孤街浪徒
孤街浪徒 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:36

    From a previous answer, try creating an empty image with a background color, then composite over.

    from wand.image import Image
    from wand.color import Color
    
    with Image(filename="sample.pdf", resolution=300) as img:
      with Image(width=img.width, height=img.height, background=Color("white")) as bg:
        bg.composite(img,0,0)
        bg.save(filename="image.png")
    

提交回复
热议问题