Faster Way to Import/Export in GIMP?

680 Views Asked by At

I have a batch processing script in GIMP that, for every image file in a directory, involves importing the image, importing a background image as a layer, doing some edits, and exporting the image. The edits take no time at all but the gimp-file-load, gimp-file-load-layer, and gimp-file-save steps take a combined total of 3-4 seconds for a 69x96 .tga image and so the batch process will take the better part of a day to handle thousands of files.

Is there a faster way to import/export these images GIMP? Maybe I can eliminate the background import step by keeping the background image open until the batch process is complete. But then what would I use in place of

(gimp-file-load-layer 1 image background)

to add the background image as a layer? I don't know of any procedures that can transfer data between two images, open in GIMP or not, without using clipboard (which I'm already using to transfer alpha channel data) or file-load.

1

There are 1 best solutions below

0
xenoid On

Not really an answer but too long for a comment:

Using two 200x200 TGA files (filled with plasma):

import time
times=[]
times.append(time.time())

image = pdb.gimp_file_load("/tmp/TGA/TGA-200x200-in.tga","/tmp/TGA/TGA-200x200-in.tga")

times.append(time.time())
layer = pdb.gimp_file_load_layer(image, "/tmp/TGA/TGA-200x200-in2.tga")

times.append(time.time())
pdb.gimp_image_add_layer(image, layer, 0)

times.append(time.time())
layerOut = pdb.gimp_image_flatten(image)

times.append(time.time())
pdb.file_tga_save(image,layerOut,"/tmp/TGA/TGA-200x200-out.tga","/tmp/TGA/TGA-200x200-out.tga", 1, 0)

times.append(time.time())

print "Steps:", [ "%5.1fms" % ((e-s)*1000) for s,e in zip(times[:-1],times[1:])]
print "Total: %5.1fms" % ((times[-1]-times[0])*1000)

Yields:

Steps: [' 97.7ms', '106.3ms', ' 20.6ms', ' 22.2ms', '102.6ms']
Total: 349.4ms

So this is 10 times faster for me. Tried variations (using file-save instead of file-tga-save for instance) without any significant changes in running time.

Yes, this is Python but AFAIK this ends up running the same code in Gimp (otherwise you have a solution...). So IMHO you have an I/O bottleneck.

Measurements on Core i5-9400H 2.50GHz with SSD, running Linux and an ext4 file system (which could be another solution...).