GIMP: Create image stack from all image files in folder

戏子无情 提交于 2019-12-02 00:41:45

"Not with script-fu". But Python is suitable to your needs. It is a simple script - the core logic should be 4 lines or so, therefore I will just write it here for you:

#!/usr/bin/python
# -*- coding: utf-8 -*-

from gimpfu import *
import os

def load_images_in_dir(image, drw, path):

    for filename in os.listdir(path):
        try:
            if filename.lower().split(".")[-1] in ("png", "jpg"):
                #import pdb as debug; debug.set_trace()
                image_id, layer_ids = pdb.gimp_file_load_layers(image,
                     os.path.join(path, filename))
                for id in layer_ids:
                    new_layer = gimp.Item.from_id(id)
                    pdb.gimp_image_add_layer(image, new_layer, 0)
        except Exception, error:
            print error



register(
        "open_images_in_dir",
        "Open all files in a directory",
        "Open all files in a directory",
        "Joao S. O. Bueno",
        "Joao S. O. Bueno",
        "2012. Creative Commons Citation Needed license",
        "Open Images in Dir as Layers...",
        "*",
        [(PF_IMAGE, "image", "the image", None),
         (PF_DRAWABLE, "drw", "the drawable", None),
         (PF_DIRNAME,"path", "Directory to Open", "."),],
        [],
        load_images_in_dir,
        menu="<Image>/File/")

main()

Note that the second part of the code is just the boilerplate for registering a function. Indeed - the call "gimp_file_load_layers" does not work as it should - as it returns a list of object "id"s which are intended not to be seem from Python - but the call to "Item.from_id" method allows one to bypass this inconvenience. This is only available in gimp-2.8, though

To get this to work in gimp 2.6 you will have to resort to open the file ina new image, and them copy the layer(s) to your target image.

Copy the script above to a GIMP's plug-ins directory (under *nix, ~/.gimp-2.8/plug-ins, for example - or check edit->prerencers->folders within GIMP for a plug-in folder) - and mark it as executable.

I just realized that the command "file" > "open as layers" in gimp 2.8 does a similar job!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!