Skip to content

Instantly share code, notes, and snippets.

@Corginyan
Created March 27, 2025 07:40
Show Gist options
  • Save Corginyan/8ecd9d255d79ef68a19d0b039f028b81 to your computer and use it in GitHub Desktop.
Save Corginyan/8ecd9d255d79ef68a19d0b039f028b81 to your computer and use it in GitHub Desktop.
Call procedure
def call_procedure(name, **kwargs):
procedure = Gimp.get_pdb().lookup_procedure(name)
if not procedure:
raise RuntimeError(f"Procedure '{name}' not found")
config = procedure.create_config()
for key, value in kwargs.items():
config.set_property(key, value)
result = procedure.run(config)
# Check if the first value is success
success = result.index(0)
if not success:
raise RuntimeError(f"Procedure '{name}' failed with error: {result.index(1)}")
# Return the result: single value if only one, or an array if more
if result.length() == 2:
return result.index(1) # Only one value, return it directly
else:
return [result.index(i) for i in range(1, result.length())]
# Usage
file = Gio.File.new_for_path(fullpath)
args = {
'image': img,
'file': file,
'compression': 0
}
call_procedure('file-png-export', **args)
if call_procedure('gimp-item-is-group', item=layer):
pass
xres, yres = call_procedure('gimp-get-monitor-resolution')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment