Windows上的GIMP从命令lin执行pythonfu脚本

2024-10-01 17:22:28 发布

您现在位置:Python中文网/ 问答频道 /正文

在Windows环境中,我想调用GIMP来执行pythonfu脚本(通过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实例”调用脚本,并通过菜单调用脚本,则脚本将完美地执行。它在源文件所在的文件夹中生成一个以''u 2.jpg'结尾的新文件。在

使用以下命令从命令提示符调用时,行为不同:

^{pr2}$

GIMP的一个实例被创建,然后关闭,但是没有创建文件,即使看到消息batch command executed successfully。在

如何从命令行中重复与“GUI实例”完全相同的行为?在


Tags: and文件实例命令行image脚本quitpdb
2条回答

从我的Windows档案:

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

经过一番周折,我得到了以下命令,它可以正常工作:

"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参数
  • 在脚本中,不要使用调用显示的函数,例如DISPLAY = gimp.Display( IMAGE ),这会使脚本失败,并出现{}

相关问题 更多 >

    热门问题