我正在尝试通过Wand在Python中将一些pdf文件转换为jpg:
from wand.image import Image as Img
from wand.color import Color
def importPdf(self):
filename, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Open File",
QtCore.QDir.currentPath())
print(filename)
if not filename:
print('error')
return
with Img(filename=filename,format='jpeg', resolution=300) as image:
image.compression_quality = 99
image.save(filename='file.jpeg')
self.open_picture()
我的问题是,结果是黑色的屏幕。转换可与png正常工作,但我无法执行OCR(通过png上的tesseract)。
我认为它来自一种透明层,但是我没有找到删除它的方法,尽管我做了几件事,例如
image.alpha_channel = False # made the same with True
image.background_color = Color('White')
在保存文件之前。
我使用的是Imagemagick V6.9,因为V7的Wand失败。
最佳答案
我遇到了同样的问题并将其修复,请在此处检查我的答案:https://stackoverflow.com/a/46612049/2686243
新增中
image.background_color = Color("white")
image.alpha_channel = 'remove'
解决了这个问题。
关于python - Python魔杖将pdf转换为黑色图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46491452/