[pygtk] Image Manipulation under pyGTK

Dieter Verfaillie dieterv at optionexplicit.be
Fri Mar 30 07:57:26 WST 2007


On Thu, 2007-03-29 at 12:50 +0900, Tim Flink wrote:
> Is it possible to use pyGTK to write anti-aliased text over an image and
> save it to disk?

I'm using cairo with pangocairo (included with GTK+/PyGTK) for this.
For example:

import cairo
import pango
import pangocairo
import math

WIDTH, HEIGHT = 400, 400

surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)
ctx.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
pctx = pangocairo.CairoContext(ctx)

pctx.set_line_width(10)
pctx.move_to(200, 100)
pctx.line_to(300, 300)
pctx.rel_line_to(-200, 0)
pctx.close_path()
pctx.stroke()

layout = pctx.create_layout()
desc =  pango.FontDescription('sans 99')
layout.set_font_description(desc)
layout.set_width(WIDTH)

pctx.move_to(WIDTH / 1.5, HEIGHT /  2)
pctx.rotate(45)
layout.set_text(u'hello')
layout.set_alignment(pango.ALIGN_CENTER)
pctx.show_layout(layout)

surface.write_to_png("test.png")


> Will it work under win32 (specifically WindowsXP)?
Sorry, I don't have a windows box to test this on,
works fine on the other os.

mvg,
Dieter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20070330/0d28f3d7/attachment.pgp


More information about the pygtk mailing list