Python、ImageMagick 和“子进程”

non*_*one 2 python parameters glob imagemagick

我正在尝试通过从 Python 脚本调用 ImageMagick 来组装图像,montage如下所示:

 command = "montage"
 args = "-tile {}x{} -geometry +0+0 \"*.png\" out.png".format( width, height)
 sys.stdout.write( "  {} {}\n".format(command, args) )
 print subprocess.call( [command, args] )
Run Code Online (Sandbox Code Playgroud)

然而,蒙太奇仅显示用法。如果我手动运行命令,一切正常。ImageMagick 应该支持 Windows 中的文件名通配,因此 *.png 被扩展。但显然,这种行为受到了压制subprocess。我是否必须使用文件名列表来glob提供信息?montage

更多信息 到目前为止谢谢。但即使当我使用:

command = "montage"
tile = "-tile {}x{}".format( width, height)
geometry = "-geometry +0+0"
infile = "*.png"
outfile = "out.png"
sys.stdout.write( "  {} {} {} {} {}\n".format(command, tile, geometry, infile, outfile) )
print [command, tile, geometry, infile, outfile]
#~ print subprocess.call( [command, tile, geometry, infile, outfile] )
print subprocess.call( ['montage', '-tile 9x6', '-geometry +0+0', '*.png', 'out.png'] )
Run Code Online (Sandbox Code Playgroud)

我收到错误:

 Magick: unrecognized option `-tile 9x6' @ error/montage.c/MontageImageCommand/1631.
Run Code Online (Sandbox Code Playgroud)

我使用的是 Windows 7、ImageMagick 6.6.5-7 2010-11-05 Q16 http: //www.imagemagick.org、Python 2.7

jd.*_*jd. 5

[command, args]您应该['montage', '-tile', '{}x{}'.format(...), '-geometry'...]作为第一个参数传递,而不是。您可能shell=True也需要。