[cairo-commit] pycairo/test to_rgba.py,NONE,1.1

Steve Chaplin commit at pdx.freedesktop.org
Sun Oct 16 19:31:33 PDT 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/test
In directory gabe:/tmp/cvs-serv7419/test

Added Files:
	to_rgba.py 
Log Message:
'SC'

--- NEW FILE: to_rgba.py ---
#!/usr/bin/env python
"""
Read a pycairo surface into a PIL image.
Requires a patched version of cairo
"""

import Image
import cairo

filename = "/tmp/file"

# 1 ImageSurface
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 150, 100)
width, height = surface.get_width(), surface.get_height()
ctx = cairo.Context (surface)

ctx.scale (width, height)

pat = cairo.LinearGradient (0.0, 0.0, 0.0, 1.0)
pat.add_color_stop_rgba (1, 0, 0, 0, 1)
pat.add_color_stop_rgba (0, 1, 1, 1, 1)

ctx.rectangle (0,0,1,1)
ctx.set_source (pat)
ctx.fill ()

data = surface.to_rgba()
im = Image.frombuffer ("RGBA", (width, height), data, "raw", "RGBA", 0,1)
im.save (filename + '.out1.png')


# 2 ImageSurface.create_from_png()
surface = cairo.ImageSurface.create_from_png ('/tmp/arc.png')
width, height = surface.get_width(), surface.get_height()
data = surface.to_rgba()
im = Image.frombuffer ("RGBA", (width, height), data, "raw", "RGBA", 0,1)
im.save (filename + '.out2.png')



More information about the cairo-commit mailing list