【问题标题】:Can I create a script for GIMP to carry out a number of processes?我可以为 GIMP 创建一个脚本来执行多个进程吗?
【发布时间】:2015-05-18 11:51:26
【问题描述】:

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

例如:

  • 调整图片大小
  • 将分辨率更改为 300 dpi
  • 阈值(黑白图像)
  • 锐化图像

如何使这个过程自动化?

【问题讨论】:

  • 可以在 GIMP 中完成吗?是的 - 但是他们,也许是 Leptonica 或 VIPS 甚至 GEGL 更合适的库来自动化这个 - 两者都有 Python 绑定 - 这应该是你选择的语言(即使你选择 GIMP,Python-fu 会比脚本更好-fu 除非你已经知道方案)
  • 如何在 Python-fu 中为 GIMP 编写脚本?

标签: image-processing automation tesseract gimp script-fu


【解决方案1】:

我刚刚整理了一个关于图形设计的答案 (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-&gt;Procedure Browser - 或者更好的是,Filters-&gt;Python-&gt;Console 并点击 Browse - 几乎相同,但有一个“应用”按钮可以实现易于测试调用,并将其复制到您的插件代码中。

【讨论】:

  • 如何在 Python Django 中实现整个过程?
猜你喜欢
  • 2023-03-10
  • 2018-09-19
  • 2018-12-02
  • 2011-09-02
  • 2020-11-19
  • 2016-05-22
  • 2012-07-02
  • 2012-12-29
  • 1970-01-01
相关资源
最近更新 更多