简体   繁体   English

如何在Python脚本中使用GIMP?

[英]How to use GIMP inside a Python script?

GIMP enables you to make plugin in in Python, what I would like to do is to call GIMP function like I would do inside one of this plugin but this return the following error since GIMP doesn't find any running GIMP Core to use. GIMP使您能够在Python中创建插件,我想要做的是调用GIMP函数,就像我在其中一个插件中所做的那样,但这会返回以下错误,因为GIMP没有找到任何正在运行的GIMP Core。

LibGimpBase-ERROR **: gimp_wire_write_msg: the wire protocol has not been initialized aborting...

I would like to know if it's possible ? 我想知道它是否可能? And if yes, how ? 如果是,怎么样?

Thanks 谢谢

GIMP's Python extensions need to be run from inside a GIMP instance. GIMP的Python扩展需要从GIMP实例内部运行。 If you want to use GIMPś API from Python you have to run a GIMP without a graphical UI (passing the -i parameter from the command line) and running a custom call to the api - with the -b command line parameter - so, you can run your python_fu_do_it program, from the command line calling: 如果你想从Python使用GIMPśAPI,你必须在没有图形用户界面的情况下运行GIMP(从命令行传递-i参数)并使用-b命令行参数运行对api的自定义调用 - 所以,你可以从命令行调用运行你的python_fu_do_it程序:

gimp -i -b \(python-fu-do-it \)

Note that this is the only way to get gimp-python extensions running: you have to run it from inside a GIMP process. 请注意,这是使gimp-python扩展运行的唯一方法:您必须从GIMP进程内部运行它。

In real life, a useful thing to do might be to make your gimp-plugin expose some functions that perform actions on images that you want, and export those through an xmlrpc or jsonrpc server - which is easily done in Python. 在现实生活中,一个有用的事情可能是让你的gimp-plugin公开一些对你想要的图像执行动作的函数,并通过xmlrpc或jsonrpc服务器导出它们 - 这很容易在Python中完成。 You then start this "image server" using the method above, and create stand-alone python script which call your gimp-using functions through xmlrpc. 然后使用上面的方法启动这个“图像服务器”,并创建独立的python脚本,通过xmlrpc调用你的gimp-using函数。

One option would be to create a listener process inside of gimp as a script (This might have implications regarding locking up the UI, experimentation will be needed here), then getting it to listen to a beanstalkd work queue. 一种选择是在gimp中创建一个监听器进程作为脚本(这可能会影响锁定UI,这里需要实验),然后让它监听beanstalkd工作队列。 then in your external processes, lodge work requests on the beanstalk queue and beanstalk can then process these orders out-of-process. 然后在您的外部进程中,在beanstalk队列上提交工作请求,然后beanstalk可以在进程外处理这些命令。

With all that said, 99% of the use cases I could imagine you wanting to do this, perhaps ImageMagick would be a more appropriate choice than gimp as its kind of designed for the sort of tasks I imagine you are interested in. 尽管如此,99%的用例我可以想象你想要这样做,也许ImageMagick会比gimp更合适,因为它的设计类似于我想象你感兴趣的那类任务。

I have to say that following statement is not true: 我不得不说以下陈述不是真的:

"GIMP's Python extensions need to be run from inside a GIMP instance." “GIMP的Python扩展需要在GIMP实例中运行。”

You do not have to run gimp in order to use its functions that are exposed through python gimpfu API. 您不必运行gimp就可以使用通过python gimpfu API公开的函数。

In any python program, for linux you just do following: 在任何python程序中,对于linux,您只需执行以下操作:

import sys  
sys.path.append('/usr/lib/gimp/2.0/python/')  
import gimpfu  

where '/usr/lib/gimp/2.0/python/' is path to gimp installation. 其中'/usr/lib/gimp/2.0/python/'是gimp安装的路径。

Regards, Karlo. 此致,卡罗。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM