# Run inside GIMP (python-fu-eval). Lists the plug-ins' procedures and menu paths, then runs Resynthesizer's # Heal Selection on a selected area of the test photo and measures how much the selected pixels changed. import json, os from gi.repository import Gimp, Gio OUT = os.environ['PROBE_OUT'] IMG = os.environ['PROBE_IMG'] pdb = Gimp.get_pdb() res = {'procedures': {}} for pat in ('.*resynth.*', '.*heal.*', '.*gmic.*', '.*uncrop.*'): for n in pdb.query_procedures(pat, '.*', '.*', '.*', '.*', '.*', '.*', '.*'): p = pdb.lookup_procedure(n) if p is None or n in res['procedures']: continue res['procedures'][n] = {'menu': list(p.get_menu_paths() or []), 'label': p.get_menu_label() or '', 'args': [a.name for a in p.get_arguments()]} heal = next((n for n in res['procedures'] if 'heal-selection' in n), None) res['heal_selection_procedure'] = heal if heal: img = Gimp.file_load(Gimp.RunMode.NONINTERACTIVE, Gio.File.new_for_path(IMG)) layer = img.get_layers()[0] w, h = img.get_width(), img.get_height() x, y, sw, sh = int(w * 0.40), int(h * 0.12), int(w * 0.10), int(h * 0.10) # a patch of mountain and sky img.select_rectangle(Gimp.ChannelOps.REPLACE, x, y, sw, sh) proc = pdb.lookup_procedure(heal); cfg = proc.create_config() for prop, val in (('run-mode', Gimp.RunMode.NONINTERACTIVE), ('image', img), ('drawable', layer)): try: cfg.set_property(prop, val) except Exception: pass try: cfg.set_core_object_array('drawables', [layer]) except Exception: pass r = proc.run(cfg) res['heal_status'] = str(r.index(0)) Gimp.Selection.none(img) out_png = os.path.join(OUT, 'heal-result.png') Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, img, Gio.File.new_for_path(out_png), None) res['heal_rect'] = [x, y, sw, sh] res['heal_output'] = out_png json.dump(res, open(os.path.join(OUT, 'plugin-probe.json'), 'w'), indent=1) pdb.lookup_procedure('gimp-quit').run(pdb.lookup_procedure('gimp-quit').create_config())