Ggr.py reads Gimp .ggr gradient files, providing a Python interface to get color values from them. There are only two methods on GimpGradient:

  • read(f) reads a .ggr file from f, either an open file or a file path. The constructor also take an optional file to read as an argument.
  • color(pos) takes a position between 0 and 1 and returns the rgb color at that point along the gradient.
>>> import ggr
>>> g = ggr.GimpGradient('Sunrise.ggr')
>>> g.color(.25)
(0.95501612668614855, 0.91457275670187077, 0.74046874445166)
>>> g.color(.5)
(0.83733161389613664, 0.37510844064480114, 0.23112679845322415)
>>> g.color(.75)
(0.42744738324707615, 0.52517311887199969, 0.83543339174375486)

This Python code is in the public domain.

Download: ggr.py

See also

  • cpt-city, a large collection of gradients.
  • My blog, where I occasionally post about other intersections of coding and graphics.

Comments

[gravatar]
Fredrik 5:57 AM on 20 Sep 2007

So you won't mind if I steal portions of it for PIL, then? ;-)

Add a comment:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.