我正在尝试将PDF转换为PNG-一切正常,但是,即使我相信已禁用它,输出图像仍然是透明的:
with Image(filename='sample.pdf', resolution=300) as img:
img.background_color = Color("white")
img.alpha_channel = False
img.save(filename='image.png')
上面产生的图像但是透明的,我也尝试了下面的方法:
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。这对我有用,而且似乎比合成图像更简单,如上所示:
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.
引用:wand.image
关于python - Python Wand将PDF转换为PNG禁用透明(alpha_channel),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27826854/