Search code examples
pythongimp

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.

Note: I am using VSCode


Solution

  • 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 (i.e., Gimp) to return before proceeding.

    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. You should double-check Gimp's interface to see if that's possible.