Making RGBA gradient strip png images with PyCairo
I find it a pain to have to open up GIMP or Photoshop to make gradient strip pngs while I'm in the middle of styling my CSS. I like to go back and forth, tweaking the gradient strip stops and reloading the web page in my browser until it looks just right.
Here's an easier way to generate them, if you prefer scripts. When you're dealing with very transparent or subtle gradients that you can barely see, a graphical interface isn't that helpful anyway. See the PyCairo docs for more on their gradients and color stops. #!/usr/bin/env pythonimport cairoWIDTH, HEIGHT = 1, 54surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context (surface)grad = cairo.LinearGradient (0, 0, 0, HEIGHT) # change to 0,0,WIDTH,0 for horiz strips
grad.add_color_stop_rgba (0,0,0,0,0)
grad.add_color_stop_rgba (0.9,0,0,0,1)ctx.rectangle(0, 0, WIDTH, HEIGHT)
ctx.set_source(grad)
ctx.fill()surface.write_to_png("gradient.png")
***********
Update 8/24/2009:
Funny, just happened to find this by accident:
http://jtauber.com/blog/2008/05/18/creating_gradients_programmatically_in_python/
Comments [0]