【发布时间】:2014-05-02 13:48:15
【问题描述】:
我有一个用 Python 为 Gimp 编写的 Scriptfu 脚本,它在现有图像上应用几个步骤,并在此过程中将其转换为索引图像。结果图像中最亮的颜色总是接近白色;我想将它设置为完全白色。方便的是,最亮的颜色始终是索引图像的颜色图中最上面的颜色,所以我只想将颜色图中的最上面的颜色设置为白色。
我在 API 描述中没有找到关于如何操作颜色图(即其中的颜色)的任何内容,所以目前我总是手动执行该步骤(Windows → Dockable Dialogs → Colormap → 单击最上面的颜色 → 在文本小部件 → 关闭对话框)。当然,Scriptfu 的整个想法是自动化所有步骤,而不仅仅是几个步骤。
谁能告诉我如何从 Python Scriptfu 脚本访问颜色图?
这是我当前的代码(由于缺乏关于如何执行的想法,它甚至没有尝试执行最后一步):
#!/usr/bin/env python
"""
paperwhite -- a gimp plugin (place me at ~/.gimp-2.6/plug-ins/ and give
me execution permissions) for making fotographs of papers
(documents) white in the background
"""
import math
from gimpfu import *
def python_paperwhite(timg, tdrawable, radius=12):
layer = tdrawable.copy()
timg.add_layer(layer)
layer.mode = DIVIDE_MODE
pdb.plug_in_despeckle(timg, layer, radius, 2, 7, 248)
timg.flatten()
pdb.gimp_levels(timg.layers[0], 0, 10, 230, 1.0, 0, 255)
pdb.gimp_image_convert_indexed(timg,
NO_DITHER, MAKE_PALETTE, 16, False, True, '')
(bytesCount, colorMap) = pdb.gimp_image_get_colormap(timg)
pdb.gimp_message("Consider saving as PNG now!")
register(
"python_fu_paperwhite",
"Make the paper of the photographed paper document white.",
"Make the paper of the photographed paper document white.",
"Alfe Berlin",
"Alfe Berlin",
"2012-2012",
"<Image>/Filters/Artistic/Paperw_hite...",
"RGB*, GRAY*",
[
(PF_INT, "radius", "Radius", 12),
],
[],
python_paperwhite)
main()
【问题讨论】:
-
为了记录,在 GIMPland 中,我们通常将术语“script-fu”保留给用 Scheme(该语言)编写的代码。 Python 脚本可以称为“Python-fu”(尽管我更喜欢将其简单地称为 GIMP 的 Python 脚本)
-
这是我为 Gimp 编写的第一个脚本,而且对这个主题是全新的,我一定会犯这样的错误,所以感谢您的澄清!
标签: python gimp script-fu gimpfu