我试图将这些常量中的颜色传递给下面的Set fontcolor函数,但每次我都会得到"无法解析颜色名称"除非我直接从GIMP对话框传递它。我甚至直接记录了传入的变量,来自数字2的值是来自日志的直接副本。任何人都可以在这里看到我做错了什么或错过了什么。感谢
FontGREEN1 = '(RGB(0,255,0,))'
FontGREEN2 = 'RGB (0.0, 1.0, 0.0, 1.0)'
#This causes the error
def setColor1 ( txtlayer, color):
color = FontGREEN1
pdb.gimp_text_layer_set_color(txtlayer, color)
#This causes the error
def setColor2 ( txtlayer ):
color = FontGREEN2
pdb.gimp_text_layer_set_color(txtlayer, color)
#this work fine, color passed directly from GIMP Dialog
def setColor3 ( txtlayer, color):
pdb.gimp_text_layer_set_color(txtlayer, color)
def setTextColor (img, drw, color ):
txtlayer = img.active_layer
setColor3(txtlayer, color)
register(
'setTextColor',
'Changes the color of the text with python',
'Changes the color of the text with python',
'RS',
'(cc)',
'2014',
'<Image>/File/Change Text Color...',
'', # imagetypes
[
(PF_COLOR,"normal_color","Green Color of the Normal Font",(0,234,0) ),
], # Parameters
[], # Results
setTextColor)
main()
答案 0 :(得分:1)
传递给GIMP的PDB函数的Color参数可以是字符串,也可以是以多种方式解释的3个数字序列。
如果你传递一个字符串,它接受CSS颜色名称,如"red"
,"blue"
- 或十六进制RGB代码,前缀为“{”,如"#ff0000"
或“{{1} “ - 但它不接受CSS函数样式语法作为字符串,即没有#0f0
作为字符串传递。
相反,您可以将3数字序列作为接受颜色值的任何参数传递。如果您的三个数字是整数,则它们被解释为每个组件的传统0-255范围。例如:
pdb.gimp_context_set_foreground((255,0,0))
将前景色设置为红色
如果任何数字是浮点数,则3序列被解释为RGB数字 在0-1.0范围内:
pdb.gimp_context_set_foreground((0,0,1.0))
将FG设置为蓝色。
所以,如果你得到一个CSS字符串,其他可能包含“RGB(...)”序列,也许最简单的方法就是去除“RGB”字符并将颜色解析为元组 - 并将该元组提供给GIMP:
"RGB(val1, val2, val3)"
如果您想要更多控制并拥有可以传递的真实“颜色”对象,请检查可以从GIMP插件导入的“gimpcolor”模块。在大多数情况下不需要它,但如果您需要生成输出或自己解析颜色名称,或者甚至做一些天真的RGB&lt; - &gt; HSL&lt; - &gt; CMYK转换,它可能很有用。 (他们没有考虑颜色配置文件或颜色空间 - 应该使用GEGL及其Python绑定)