gimp - 当前图像中的 Gimp python 脚本
问题描述
我正在尝试使用 GIMP 进行图像处理,但我在第一个障碍中失败了:
在 GIMP 中加载图像后,我想运行一个注册脚本来运行一个函数 - 只需将整个图像旋转 90 度,然后显示一条消息。
#!/usr/bin/env python
import os
import sys
import time
from gimpfu import *
def simple_test():
num = 90
image = gimp.pdb # not sure if this is calling the active image
drawable = pdb.gimp_image_get_active_layer(image)
rotate_it(image, 90)
def rotate_it(image, deg):
msg = "simple_test!! " + str(deg) + "\n"
pdb.gimp_image_rotate(gimp.pdb, num)
gimp.message(msg)
register(
"simple_test",
"A simple Python-Fu plug-in",
"When run this plug-in rotates an image 90 degrees",
"Ghoul Fool",
"Ghoul Fool",
"2020",
"simple test",
"",
[],
[],
simple_test,
menu="<Image>/Filters/simple-test",
)
main()
更重要的是尝试获取一些错误消息/日志/控制台输出以找出我哪里出错了——只是默认情况下似乎不会显示。
解决方案
看起来您确实错误地调用了当前图像。也许这个示例脚本可以帮助你:
#!/usr/bin/env python
# Tutorial available at: https://www.youtube.com/watch?v=nmb-0KcgXzI
# Feedback welcome: jacksonbates@hotmail.com
from gimpfu import *
def hello_warning(image, drawable):
pdb.gimp_message("Hello world!")
register(
"python-fu-hello-warning",
"SHORT DESCRIPTION",
"LONG DESCRIPTION",
"Jackson Bates", "Jackson Bates", "2015",
"Hello warning",
"", # type of image it works on (*, RGB, RGB*, RGBA, GRAY etc...)
[
(PF_IMAGE, "image", "takes current image", None),
(PF_DRAWABLE, "drawable", "Input layer", None)
],
[],
hello_warning, menu="<Image>/File") # second item is menu location
main()
我还建议这个家伙关于 gimp python fu 的视频系列:https ://www.youtube.com/watch?v=nmb-0KcgXzI 。不幸的是,考虑到调试,官方文档(在我看来)缺乏对初学者的友好性。
推荐阅读
- javascript - 为什么我得到 [object object ] 而不是 JSON?
- python - 如何在训练过程中查看 PyTorch 中的 weight_decay 损失?
- c# - WPF,如何将图像插入 RichTextBox
- git - git Blame -L '/^<<< >>>/' -- {文件名}
- docker - 无法使用自定义的最新 Firefox 和声音创建 Docker
- selenium - 为什么 XCUITest 对 iOS 应用程序运行太慢?
- android - 匕首每次从单例类创建新实例
- c# - 如何使用firesharp从firebase获取所有数据
- php - 从程序迁移到 OOP PHP 的正确方法 - “对象”应该是什么?
- python-3.x - 使用python宏发送键盘/鼠标输入保持目标窗口背景