在Windows环境中,我想调用GIMP来执行python-fu脚本(通过BAT文件),但是我正在使用的命令行调用未产生预期的结果。
例如,考虑以下名为makeafile_and_quit.py
的python-fu脚本,该脚本位于我的GIMP的plug-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()
如果从GIMP的“GUI实例”调用脚本,则可以完美地执行脚本,并通过菜单进行调用。它在与源文件相同的文件夹中生成一个以'_2.jpg'结尾的新文件。
使用以下命令从命令提示符处调用时,该行为是不同的:
"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实例”完全相同的行为?
最佳答案
经过多番摆弄之后,我到达了下面的命令,该命令可以按需工作:
注意:
gimp-console-2.8.exe
而不是gimp-2.8.exe
来避免在执行结束时不必要的击键python-fu-
-
而不是_
RUN-NONINTERACTIVE
参数DISPLAY = gimp.Display( IMAGE )
,这些函数会使脚本因gimp-console-2.8.exe
失败关于python - Windows上的GIMP-从命令行执行python-fu脚本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41970313/