如何在 Python 脚本中使用 GIMP?

发布于 2024-12-17 04:11:01 字数 268 浏览 4 评论 0原文

GIMP 使您能够在 Python 中制作插件,我想做的是调用 GIMP 函数,就像我在这个插件之一中所做的那样,但这会返回以下错误,因为 GIMP 找不到任何正在运行的 GIMP Core 来使用。

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

我想知道是否可以?如果是,怎么办?

谢谢

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九厘米的零° 2024-12-24 04:11:02

GIMP 的 Python 扩展需要从 GIMP 实例内部运行。如果您想从 Python 使用 GIMPś API,则必须在没有图形 UI 的情况下运行 GIMP(从命令行传递 -i 参数)并运行对 api 的自定义调用 - 使用 -b 命令行参数 - 因此,您可以从命令行调用运行您的 python_fu_do_it 程序:

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

请注意,这是运行 gimp-python 扩展的唯一方法:您必须从 GIMP 内部运行它 过程。

在现实生活中,一件有用的事情可能是让您的 gimp 插件公开一些对您想要的图像执行操作的函数,并通过 xmlrpc 或 jsonrpc 服务器导出这些函数 - 这在 Python 中很容易完成。然后,您使用上面的方法启动这个“图像服务器”,并创建独立的 python 脚本,该脚本通过 xmlrpc 调用使用 gimp 的函数。

GIMP's Python extensions need to be run from inside a GIMP instance. 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:

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.

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. You then start this "image server" using the method above, and create stand-alone python script which call your gimp-using functions through xmlrpc.

甩你一脸翔 2024-12-24 04:11:02

一种选择是在 gimp 内部创建一个侦听器进程作为脚本(这可能会对锁定 UI 产生影响,这里需要进行实验),然后让它侦听 beanstalkd 工作队列。然后在您的外部流程中,向 beanstalk 队列提交工作请求,然后 beanstalk 可以在流程外处理这些订单。

话虽如此,我可以想象 99% 的用例您想要这样做,也许 ImageMagick 比 gimp 更合适,因为它是为我认为您感兴趣的任务而设计的。

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. then in your external processes, lodge work requests on the beanstalk queue and beanstalk can then process these orders out-of-process.

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.

骑趴 2024-12-24 04:11:02

我不得不说下面的说法是不正确的:

“GIMP 的 Python 扩展需要从 GIMP 实例内部运行。”

您不必运行 gimp 即可使用其通过 python gimpfu API 公开的功能。

在任何Python程序中,对于Linux你只需执行以下操作

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


'/usr/lib/gimp/2.0/python/' 是 gimp 安装路径。

问候,卡洛。

I have to say that following statement is not true:

"GIMP's Python extensions need to be run from inside a GIMP instance."

You do not have to run gimp in order to use its functions that are exposed through python gimpfu API.

In any python program, for linux you just do following:

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.

Regards, Karlo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文