[cairo] image scaling in cairo, python
paragate at gmx.net
Sun May 25 05:00:09 PDT 2008
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
> #set resampling filter
> canvas = cairo.ImageSurface(cairo.FORMAT_ARGB32,320,240)
> ctx = cairo.Context(canvas)
> >From reading your posts to other lists I believe PIL is simpler. But
> it depends on your use case of course.
> On Sat, May 24, 2008 at 12:04 PM, Wolfgang Lipp <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:
>> cairo mailing list
>> cairo at cairographics.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cairo