Python Wand将PDF转换为PNG禁用透明(alpha_channel) [英] Python Wand convert PDF to PNG disable transparent (alpha_channel)

查看:970
本文介绍了Python Wand将PDF转换为PNG禁用透明(alpha_channel)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将PDF转换为PNG - 这一切都运行正常,但是,即使我相信我已将其禁用,输出图像仍然是透明的:

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(filename='sample.pdf', resolution=300) as img:
    img.background_color = Color("white")
    img.alpha_channel = False
    img.save(filename='image.png')

以上产生了图像但透明,我也尝试了以下内容:

The above produces the images but are transparent, I also tried the below:

with Image(filename='sample.pdf', resolution=300, background=Color('white')) as img:
    img.alpha_channel = False
    img.save(filename='image.png')

产生此错误:

Traceback (most recent call last):
  File "file_convert.py", line 20, in <module>
    with Image(filename='sample.pdf', resolution=300, background=Color('white')) as img:
  File "/Users/Frank/.virtualenvs/wand/lib/python2.7/site-packages/wand/image.py", line 1943, in __init__
    raise TypeError("blank image parameters can't be used with image "
TypeError: blank image parameters can't be used with image opening parameters


推荐答案

我也有一些PDF转换为PNG。这对我有用,似乎比合成图像更简单,如上所示。:

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.

参考erence: wand.image

这篇关于Python Wand将PDF转换为PNG禁用透明(alpha_channel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆