Python Wand convert PDF to PNG disable transparent (alpha_channel)

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

    I also had some PDFs to convert to PNG. This worked for me and seems simpler than compositing images, as shown above.:

    all_pages = Image(blob=self.pdf)        # PDF will have several pages.
    single_image = all_pages.sequence[0]    # Just work on first page
    with Image(single_image) as i:
        i.format = 'png'
        i.background_color = Color('white') # Set white background.
        i.alpha_channel = 'remove'          # Remove transparency and replace with bg.
    

    Reference: wand.image

提交回复
热议问题