【发布时间】:2015-04-21 12:53:48
【问题描述】:
所有迹象似乎都表明我的脚本可以在 Linux 环境中完全运行,据我所知,唯一阻止它在 Windows 中运行的就是我使用了 sh,这非常简单:
from sh import convert
convert(inputfile, '-resize', r, '-quality', q, '-strip', outputfile)
这转换为 bash 行:
convert image.jpg -resize 350x350 -quality 80 -strip ./small/export.jpg
其中r 和q 变量是任何给定的分辨率或质量。
在 Windows 中运行它当然会引发错误,因为“sh”在 Windows 中完全不起作用:(我尝试用已弃用的 pbs 替换“sh”,但没有任何运气。这就是我的到目前为止:
import pbs
pbs.convert('-resize', r, '-quality', q, '-strip', inputfile, outputfile)
引发的错误是:
File "C:\Python27\lib\site-packages\pbs.py", line 265, in _create
if not path: raise CommandNotFound(program)
pbs.CommandNotFound: convert
问题:
如何在 Windows 环境中从我的脚本中成功传递这些 ImageMagick 命令?
【问题讨论】:
-
为什么不使用 subprocess 和 popen 或调用?
-
@IronManMark20:我试图弄清楚如何使用它们。 subprocess 似乎是正确的方向,但它不像 sh 那样对新手友好。
标签: python subprocess porting imagemagick-convert