所有迹象似乎都表明我的脚本可以在 Linux 环境中完全运行,据我所知,唯一阻止它在 Windows 中运行的是我使用sh https://pypi.python.org/pypi/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
and q
变量是任何给定的分辨率或质量。
在 Windows 中运行它当然会引发错误,因为 'sh' 在 Windows 中完全不起作用:( 我尝试将 'sh' 替换为已弃用的pbs https://pypi.python.org/pypi/pbs,但我没有任何运气。这是我到目前为止所得到的:
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 命令?