It is currently Sat Jun 29, 2024 10:15 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Calling GIMP Plug-in From Command Line - on Windows
PostPosted: Wed Nov 29, 2023 11:44 am  (#1) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3999
Location: Canada
After a long period of fighting trying to call my plug-in from command line (on Windows).
I tried with help of
1. This syntax on stackoverflow
2. Debugging Python Fu Scripts on Windows on gimp-forum.net
3. You cannot use single-quotes on a Windows command line on gimp-forum.net

This is my finding/success.

I have a plug-in as a test with code below:
#!/usr/bin/env python
#test-command.py

from gimpfu import *
def test_command(color,filename):
    pdb.gimp_message("1");
    new_image = pdb.gimp_image_new(600,400,RGB)
    pdb.gimp_message("2");
    #new_display = pdb.gimp_display_new(new_image) #this will error in commandline mode with no interface -i
    pdb.gimp_message("3");
    new_layer = pdb.gimp_layer_new(new_image,600,400,RGBA_IMAGE,'new-layer',100,LAYER_MODE_NORMAL)
    pdb.gimp_message("4");
    pdb.gimp_image_insert_layer(new_image,new_layer,None,0)
    pdb.gimp_message("5");
    pdb.gimp_context_set_foreground(color)
    pdb.gimp_message("6");
    pdb.gimp_edit_fill(new_layer,FILL_FOREGROUND)
    pdb.gimp_message("7");
    filename = filename + ".png" #set the file name to have extension
    pdb.gimp_message("8");
    pdb.file_png_save_defaults(new_image,new_layer,filename,filename)
    pdb.gimp_message("9");
    #pdb.gimp_display_delete(new_display) #this will error in commandline mode with no interface -i
    pdb.gimp_message("10");

register(
    "python_fu_test_command",
    "Test from Command Line",
    "for Testing from Command Line",
    "TT",
    "TT",
    "November 29, 2023",
    "Test Command...",
    "",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [
    #INPUT BEGINS
    # (PF_IMAGE, "img", "Image", None),
    # (PF_DRAWABLE,   "layer", "Drawable", None),
    (PF_COLOR, "color", "Color:", (0, 255, 0) ), # extra param is RGB triple
    (PF_STRING, "filename", "Filename:", "foo"),  # alias PF_VALUE
    # (PF_STRING, "color", "Shirt Color (in Hex):", "c3002e"),  # alias PF_VALUE
    # (PF_OPTION, "darklight",   "Choose Dark/Light:", 0, ["Dark","Light"]),
    # (PF_INT, "displaceY", "Displace-Y:", 35),
    # #(PF_COLOR, "color", "Shirt Color:", (195, 0, 46)),
    # (PF_DIRNAME, "inputdir", "Designs Parent Directory:", 0),
    #(PF_DIRNAME, "outputdir", "Output Directory:", 0),
    #INPUT ENDS
    ],
    [],
    test_command,
    menu="<Image>/Python-Fu")

main()
#

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.


This plug-in simply accepts a color create an image with that color and then save it as a filename given (with .png appended to the filename given).

here are my successful calls from windows command line
file will be created in current folder (thisisdope.png) where command is called from (run without interface [-i])
"C:\Users\tintran\AppData\Local\Programs\GIMP 2\bin\gimp-2.10.exe" -i --batch-interpreter python-fu-eval -b "pdb.python_fu_test_command((255,0,255),\"thisisdope\")" -b "pdb.gimp_quit(1)"

file will be created in explicit path in (C:\Users\tintran\foo11.png) doesn't matter where command is called from (run without interface [-i])
"C:\Users\tintran\AppData\Local\Programs\GIMP 2\bin\gimp-2.10.exe" -i --batch-interpreter python-fu-eval -b "pdb.python_fu_test_command((255,0,255),\"C:\\Users\\tintran\\foo11\")" -b "pdb.gimp_quit(1)"

runs with interface (opens gimp, runs plug-in then quit GIMP)
"C:\Users\tintran\AppData\Local\Programs\GIMP 2\bin\gimp-2.10.exe" -n --batch-interpreter python-fu-eval -b "pdb.python_fu_test_command((255,0,255),\"C:\\Users\\tintran\\foo12\")" -b "pdb.gimp_quit(1)"


while running -i (with no interface) pdb.gimp_message will output to command/run window.

Why this is here?
It's to help myself in the future if I have the need to do this then it'll save me from fighting again.
This came up because I had a missed client, it looked like a fun project, and they said ideally they want the ability to run script from command line. So I have never done that before so I looked into a bit. But sadly the client went silent so I am guessing they went with another seller. But I wanted to do this anyways just in case future clients want this ability then I can save myself or others some time fighting/fiddling.

My other option was to learn ImageMagick but I am not familiar with it or don't know it at all, I'd rather stick with GIMP plug-in solution since I feel like I have more control over operations in GIMP plug-in.

Pretty happy to share this post as it could save you nearly 3 hours (if you were like me).

_________________
TinT


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts How do you run GIMP from the command line?

1

No new posts Attachment(s) G'MIC> Pattern> Strip command line?

2

No new posts GEGL command line and layer modes?

2

No new posts Attachment(s) Python calling G'MIC filter? (Solved)

4

No new posts Attachment(s) Don't work procedures plug-in-bump-map, plug-in-displace

2



* Login  



Powered by phpBB3 © phpBB Group