我可以为 GIMP 创建一个脚本来执行多个进程吗?

Can I create a script for GIMP to carry out a number of processes?

我想在将图像发送到 Tesseract 进行 OCR 之前处理图像。

例如:

我怎样才能使这个过程自动化?

我刚刚整理了一个关于图形设计的答案 (https://graphicdesign.stackexchange.com/questions/53919/editing-several-hundred-images-gimp/53965#53965 ),它是为没有编程技能的人准备的 GIMP 自动化入门 - 理解 Python-fu 也应该很好。

在同一个答案上,有指向官方文档的链接,以及一个如何创建小脚本的示例。您应该让他们浏览 GIMP 的 PDB 以了解您想要的确切收益。

但是,总而言之,您可以像这样创建 Python 文件:

from gimpfu import *
import glob

def auto():
    for filename in glob(source_folder  + "/*.png"):
        img = pdb.gimp_file_load(source_folder + filename, source_folder + filename)
        # place the PDB calls to draw on the image before your interation here

        #disp = pdb.gimp_display_new(img)

        pdb.gimp_image_merge_visible_layers(img, CLIP_TO_IMAGE)
        pdb.gimp_file_save(img, img.layers[0], dest_folder + filename, dest_folder + filename)
        # pdb.gimp_display_delete(disp)
        pdb.gimp_image_delete(img)  # drops the image from gimp memory


register("batch_process_for_blah",
         "<short dexcription >Batch Process for Bla",
         "<Extended description text>",
         "author name",
         "license text",
         "copyright note",
         "menu label for plug-in",
         "", # image types for which the plug-in apply - "*" for all, blank for plug-in that opens image itself
         [(PF_DIRNAME, "source_folder", "Source Folder", None),
          (PF_DIRNAME, "dest_folder", "Dest Folder", None)], # input parameters - 
         [], # output parameters
         menu="<Image>/File", # location of the entry on the menus
         )
main()

要在 for 循环中找到所需的操作,转到 Help->Procedure Browser - 或者更好,Filters->Python->Console 并点击 Browse - 它几乎相同,但有一个 "apply" 按钮可以轻松测试调用,并将其复制到您的插件代码中。