我正在尝试通过Python中的Wand将一些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')在保存文件之前。我使用的是ImagemagickV6.9,因为V7无法使用Wand。
发布于 2017-10-07 02:44:38
我也有同样的问题,并解决了它,在这里检查我的答案:https://stackoverflow.com/a/46612049/2686243
添加
image.background_color = Color("white")
image.alpha_channel = 'remove'解决了问题。
发布于 2017-10-02 20:50:12
因为我没有通过wand api找到-flatten,所以我最终通过imagemagick的os.system + convert.exe找到了它。它做到了这一点。
cmd = "convert -units PixelsPerInch -density 300 -background white -flatten " + filename + " converted_pdf.jpg"
print(cmd)
os.system(cmd)https://stackoverflow.com/questions/46491452
复制相似问题