Tfb*_*fb9 6 python command-line batch-file gimp python-fu
在 Windows 环境中,我想调用 GIMP 来执行 python-fu 脚本(通过 BAT 文件),但是我使用的命令行调用没有产生预期的结果。
例如,考虑以下名为 的 python-fu 脚本makeafile_and_quit.py,它位于我的 GIMPplug-ins文件夹中。其目的是加载现有图像并以不同名称保存:
#!/usr/bin/env python
# Sample call from GIMP's 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()
Run Code Online (Sandbox Code Playgroud)
如果从 GIMP 的“GUI 实例”调用脚本,脚本将完美执行,通过菜单调用脚本。它会在与源文件相同的文件夹中生成一个以“_2.jpg”结尾的新文件。
使用以下命令从命令提示符调用时,行为会有所不同:
"C:\Program Files\GIMP 2\bin\gimp-2.8.exe" --batch '("makeafile_and_quit.py")' -b "(gimp-quit 0)"
Run Code Online (Sandbox Code Playgroud)
GIMP 的一个实例被创建,然后关闭,但即使batch command executed successfully看到消息,也不会创建任何文件。
如何从命令行重复与“GUI 实例”完全相同的行为?
经过多次摆弄,我得到了以下命令,该命令可以按需要工作:
"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" --verbose --batch "(python-fu-makeafile-and-quit-script RUN-NONINTERACTIVE)" --batch "(gimp -退出 0)"
请注意:
gimp-console-2.8.exe而不是gimp-2.8.exe避免在执行结束时不必要的击键python-fu--'s 而不是_'sRUN-NONINTERACTIVE参数DISPLAY = gimp.Display( IMAGE ),这会使脚本失败gimp-console-2.8.exe