[英]Open all images in a folder on gimp using Python
I get something similar using:我得到类似的东西:
gimp = r'C:\Program Files\GIMP 2\bin\gimp-2.10.exe'
os.chdir(folder)
filesnames= os.listdir()
for f in filesnames:
actfile = folder+'\\'+f
p = subprocess.Popen([gimpcamin, actfile])
p.wait()
But this script can open only one image and the next image opens when I close Gimp.但是这个脚本只能打开一个图像,当我关闭 Gimp 时会打开下一个图像。
Note: I am using VSCode注意:我正在使用 VSCode
I believe that the issue is that you have p.wait()
immediately after p = subprocess.Popen([gimpcamin, actfile])
, which makes it wait for that command (ie, Gimp) to return before proceeding.我认为问题在于您在p = subprocess.Popen([gimpcamin, actfile])
之后立即有p.wait()
,这使得它在继续之前等待该命令(即 Gimp)返回。
You should try:你应该试试:
gimp = r'C:\Program Files\GIMP 2\bin\gimp-2.10.exe'
os.chdir(folder)
filesnames= os.listdir()
processes = []
for f in filesnames:
actfile = folder+'\\'+f
processes.append(subprocess.Popen([gimpcamin, actfile]))
# wait for all processes to finish
for p in processes:
p.wait()
I'm not sure that this what you really want.我不确定这是你真正想要的。 I suspect you rather have just another Window of Gimp open for each image, rather than opening a whole different instance.我怀疑您宁愿为每个图像打开另一个 Gimp 窗口,而不是打开一个完全不同的实例。 You should double-check Gimp's interface to see if that's possible.您应该仔细检查 Gimp 的界面,看看是否可行。
If this is all you do, you can just use gimp /path/dir/*.png
in your shell, like most Unix utilities, the gimp
command accepts several files.如果这就是你所做的一切,你可以在你的 shell 中使用gimp /path/dir/*.png
,就像大多数 Unix 实用程序一样, gimp
命令接受几个文件。
If you want to do it in Python:如果您想在 Python 中执行此操作:
gimpCmd=[r'C:\Program Files\GIMP 2\bin\gimp-2.10.exe','-n'] # -n to get a new Gimp instance, if necessary
subprocess.Popen(gimpCmd+os.listdir())
Of course this is possibly limited by the acceptable command line length, but in practice you'll be out of RAM (and display real estate) before you hit that limit.当然,这可能会受到可接受的命令行长度的限制,但实际上,在达到该限制之前,您将用完 RAM(并显示不动产)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.