我试图通过调用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] )然而,蒙太奇只显示用法。如果我手动运行该命令,一切都正常。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'] )我收到一个错误:
Magick: unrecognized option `-tile 9x6' @ error/montage.c/MontageImageCommand/1631.我在Windows7上,ImageMagick 6.6.5-7 2010-11-05 Q16 http://www.imagemagick.org,Python2.7
发布于 2011-02-15 21:52:09
而不是[command, args],您应该传递['montage', '-tile', '{}x{}'.format(...), '-geometry'...]作为第一个参数。您可能也需要shell=True。
发布于 2011-02-15 23:03:23
jd已经给出了解决方案,但您没有仔细阅读;)
这是不正确的:
subprocess.call( ['montage', '-tile 9x6', '-geometry +0+0', '*.png', 'out.png'] )这是正确的:
subprocess.call( ['montage', '-tile', '9x6', '-geometry', '+0+0', '*.png', 'out.png'] )发布于 2011-02-15 21:53:18
subprocess.call期望将整个命令拆分为一个列表(每个参数作为列表的一个单独元素)。尝试:
import shlex
command = "montage"
args = "-tile {}x{} -geometry +0+0 \"*.png\" out.png".format( width, height)
subprocess.call( shlex.split('{} {}'.format(command, args)) )https://stackoverflow.com/questions/5009907
复制相似问题