首页 > 解决方案 > Imagemagick 通过 Python 转换

问题描述

我有一堆我想使用 python 转换为 .tiffs 的 PDFS。

data_path = " some path "
tiff path = " some path "
data_list = os.listdir(data_path)

for f in data_list:
   if (os.path.isfile(os.path.join(data_path, f)) and f.endswith(".pdf")):

      process = subprocess.Popen(
         ["convert", os.path.join(data_path, f), "-density 300", os.path.join(tiff_path, f+".tiff")],
         stdout = subprocess.PIPE,
         stderr = subprocess.PIPE
      )
      stdout, stderr = process.communicate()
      print("stdout", stdout)
      print("stderr", stderr)

如果没有“-density 300”,上述工作正常。当我使用该选项(或任何其他选项)时,它会引发以下错误:

stdout b''
stderr b"convert: unrecognized option `-density 300' @ error/convert.c/ConvertImageCommand/1427.\n"
stdout b''
stderr b"convert: unrecognized option `-density 300' @ error/convert.c/ConvertImageCommand/1427.\n"
stdout b''
stderr b"convert: unrecognized option `-density 300' @ error/convert.c/ConvertImageCommand/1427.\n"

该命令在终端上运行良好。任何修复它的帮助表示赞赏。提前致谢。

注意:我在 MacOS 上。

标签: pythonmacosoperating-systemimagemagick

解决方案


推荐阅读