GIMP on Windows - executing a python-fu script from the command line

In a Windows environment, I would like to call GIMP to execute a python-fu script (via a BAT file), but the command line call that I use does not give the expected results.

For example, consider the following python-fu script with a name makeafile_and_quit.pythat is in my GIMP folder plug-ins. Its purpose is to upload an existing image and save it under a different name:

#!/usr/bin/env python

# Sample call from GIMP python-fu console:
# pdb.python_fu_makeafile_and_quit_script()

from gimpfu import *

def makeafile_and_quit( ) :

    FILEPATH   = 'C:\\path\\to\\file.JPG'
    IMAGE      = pdb.gimp_file_load( FILEPATH,  FILEPATH )

    pdb.gimp_file_save( IMAGE, pdb.gimp_image_get_active_drawable( IMAGE ), FILEPATH + '_2.jpg',  FILEPATH + '_2.jpg' )

    pdb.gimp_quit(0)

    return


# PLUGIN REGISTRATION
# This is the plugin registration function
register(
    'makeafile_and_quit_script',
    'v0.0',
    'A new concept',
    'Author',
    'Author',
    'Just now',
    '<Toolbox>/MyScripts/This will make a file and _QUIT',
    '',
    [],
    [],
    makeafile_and_quit
    )

main()

The script runs flawlessly if called from a "GUI instance" of GIMP, invoking the script through the menu. It creates a new file ending with "_2.jpg" in the same folder as the original file.

When called from the command line, the behavior is different from the following:

"C:\Program Files\GIMP 2\bin\gimp-2.8.exe" --batch '("makeafile_and_quit.py")' -b "(gimp-quit 0)"

GIMP, , , batch command executed successfully.

, "GUI-", ?

+4
2

Windows:

gimp -idf -b "yourscript" -b "pdb.gimp_quit(1)"
0

, :

"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" --verbose --batch "(python-fu-makeafile-and-quit- script RUN-NONINTERACTIVE)" --batch "(gimp-quit 0)"

:

  • gimp-console-2.8.exe gimp-2.8.exe, .
  • python-fu-
  • - _
  • ( ) RUN-NONINTERACTIVE
  • script, , , DISPLAY = gimp.Display( IMAGE ), script gimp-console-2.8.exe
0

Source: https://habr.com/ru/post/1668467/


All Articles