Gimp Python-Fu

De Banane Atomic
Aller à la navigationAller à la recherche

Liens

Template

  • Mettre le scripts dans ~/.gimp-2.8/plug-ins
  • Le rendre exécutable
  • redémarrer GIMP
mon_plugin.py
#!/usr/bin/env python

from gimpfu import *

def do_it(image, layer, initstr, font, size, color) :
    #...

register(
    "python_fu_mon_plugin",  # The name of the command that you can call from the command line or from scripting
    "Info",  # Information about the plug-in that displays in the procedure browser
    "Does this and that",  # Help for the plug-in
    "Me",  # The plug-in's author
    "Me",  # The copyright holder
    "2016",  # The copyright date
    "<Image>/Filters/Misc/My Proc",  # The label that the plug-in uses in the menu
    "RGB*, GRAY*, INDEXED*",  # The types of images the plug-in is made to handle
    [
        (PF_STRING, "string", "Text string", 'xxx'),
        (PF_FONT, "font", "Font face", "Sans"),
        (PF_SPINNER, "size", "Font size", 50, (1, 3000, 1)),
        (PF_COLOR, "color", "Text color", (1.0, 0.0, 0.0))
    ],  # The parameters for the plug-in's method
    [],  # The results of the plug-in's method
    do_it)  # The name of the method to call in your Python code

main()

Exemples

Brighter

Python.svg
def make_brighter(image, layer) :

    layer2 = layer.copy()
    layer2.opacity = 75.0
    layer2.mode = SOFTLIGHT_MODE
    layer2.name = "2"
    image.add_layer(layer2, 0)
    
    pdb.gimp_desaturate_full(layer2, 2)  # 2 = GimpDesaturateMode.GIMP_DESATURATE_AVERAGE
    
    pdb.gimp_invert(layer2)
    
    # 2 last args: Blur in horizontal direction and Blur in vertical direction
    pdb.plug_in_gauss_rle(image, layer2, 15, True, True)
    
    layer3 = layer2.copy()
    layer3.opacity = 50.0
    layer3.name = "3"
    image.add_layer(layer3, 0)
    
    layer4 = layer.copy()
    layer4.opacity = 15.0
    layer4.mode = DARKEN_ONLY_MODE
    layer4.name = "4"
    image.add_layer(layer4, 0)

GIMP Batch Mode

Bash.svg
gimp -i -b "(python-fu-mon-plugin RUN-NONINTERACTIVE \"mon_image.jpg\")" -b "(gimp-quit 0)"
Pour le nom du plugin, remplacer les _ par des -
Python.svg
def do_it(filepath) :

    image = pdb.gimp_file_load(filepath, filepath)
    layer = pdb.gimp_image_get_active_layer(image)

    # appel de python_fu_mon_plugin
    pdb.python_fu_mon_plugin(image, layer)

    merged_layer = pdb.gimp_image_merge_visible_layers(image, CLIP_TO_IMAGE)
    pdb.gimp_file_save(image, merged_layer, filepath, filepath)
    # libère la mémoire
    pdb.gimp_image_delete(image)

register(
    "python_fu_mon_plugin_cmd",  # The name of the command that you can call from the command line or from scripting
    "Info",  # Information about the plug-in that displays in the procedure browser
    "Aide pour le plugin",  # Help for the plug-in
    "Me",  # The plug-in's author
    "Me",  # The copyright holder
    "2016",  # The copyright date
    "",  # The label that the plug-in uses in the menu: ici vide car seulement utilisé en ligne de commande
    "RGB*",  # The types of images the plug-in is made to handle (RGB*, GRAY*, INDEX*)
    [
        (PF_STRING, "filepath", "filepath", "*.jpg")
    ],  # The parameters for the plug-in's method
    [],  # The results of the plug-in's method
    do_it)  # The name of the method to call in your Python code