[cairo] image scaling in cairo, python

Gerdus van Zyl gerdusvanzyl at gmail.com
Sun May 25 05:33:14 PDT 2008


The best source of info for pycairo is the tutorial at
http://www.tortall.net/mu/wiki/CairoTutorial;
and then of course the docs at http://www.cairographics.org/documentation/;
especialy the cookbook and samples. There is no really comprehensive guide
on cairo at the moment.

Most of the more advanced question I had were solved by reading code from
software that uses cairo eg: GTK and Mono Moonlight come to mind.

Have fun with cairo!

~Gerdus

On Sun, May 25, 2008 at 2:00 PM, Wolfgang Lipp <paragate at gmx.net> wrote:

>
> YAY, it WORKS! thanks so much, the first useful pointer in days. do you
> happen to know a site where people post useful recipes concerning cairo /
> other graphics processing in pyhon (other than the obvious aspn cookbook)?
> any comprehensive guide to caito / pycairo?
>
> you know i find it hard to figure out to do stuff like this in cairo. as
> soon as i know, it's not so bad, i'll simply wrap it as `def
> scale_image(...)` and presto. it's just those working code examples for
> various tasks that i need. i've already hatched a few methods to draw simple
> shapes, now i have raster scaling @ ffx3 quality. i am happy.
>
> cheers & ~flow
>
>
> Gerdus van Zyl wrote:
>
> To resample a png in pyCairo you need this:
> import cairo
>
> img = cairo.ImageSurface.create_from_png("in.png")
> width = img.get_width()
> height = img.get_height()
>
> imgpat = cairo.SurfacePattern(img)
>
> scaler = cairo.Matrix()
> #1 = 100%; 2 = 50%;0.5 = 200%
> scaler.scale(2,2) #50% downscale in this case
> imgpat.set_matrix(scaler)
>
> #set resampling filter
> imgpat.set_filter(cairo.FILTER_BEST)
>
> canvas = cairo.ImageSurface(cairo.FORMAT_ARGB32,320,240)
> ctx = cairo.Context(canvas)
>
> ctx.set_source(imgpat)
> ctx.paint()
>
> canvas.write_to_png("out.png")
>
> >From reading your posts to other lists I believe PIL is simpler. But
> it depends on your use case of course.
>
> ~Gerdus
>
>
> On Sat, May 24, 2008 at 12:04 PM, Wolfgang Lipp <paragate at gmx.net> <paragate at gmx.net> wrote:
>
>
>  [also posted to: comp.lang.python]
>
> hi all,
>
> i've heard cairo has become the image scling library for firefox3. is
> that true? wonderful, i want to do that in python. there's a python
> interface for cairo, right? i've used it before to do simple vector
> stuff. seems to work. however, i haven't been able to find relevant
> pointers via google. (rant: your mailman interface here is incredibly
> unsuited to promote open discussions).
>
> so do you have any pointers on how to resize a raster image with python
> using cairo? i've been jumping through hoops for a while now, and i
> believe it should be easier.
>
> cheers and ~flow
>
> ps. related (long) posts:
> http://groups.google.com/group/pyglet-users/browse_frm/thread/44253ad01d809da5/cd051e6bced271e1#cd051e6bced271e1
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/5df65d99cff0d7bb#
>
>
> _______________________________________________
> cairo mailing listcairo at cairographics.orghttp://lists.cairographics.org/mailman/listinfo/cairo
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080525/f6a24d48/attachment.html 


More information about the cairo mailing list