<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
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? <br>
<br>
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.<br>
<br>
cheers & ~flow<br>
<br>
Gerdus van Zyl wrote:
<blockquote
cite="mid:91882ea90805240405m4f0e95c8wb0e9b8b8e1b06dba@mail.gmail.com"
type="cite">
<pre wrap="">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 <a class="moz-txt-link-rfc2396E" href="mailto:paragate@gmx.net"><paragate@gmx.net></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">[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:
<a class="moz-txt-link-freetext" href="http://groups.google.com/group/pyglet-users/browse_frm/thread/44253ad01d809da5/cd051e6bced271e1#cd051e6bced271e1">http://groups.google.com/group/pyglet-users/browse_frm/thread/44253ad01d809da5/cd051e6bced271e1#cd051e6bced271e1</a>
<a class="moz-txt-link-freetext" href="http://groups.google.com/group/comp.lang.python/browse_frm/thread/5df65d99cff0d7bb#">http://groups.google.com/group/comp.lang.python/browse_frm/thread/5df65d99cff0d7bb#</a>
_______________________________________________
cairo mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cairo@cairographics.org">cairo@cairographics.org</a>
<a class="moz-txt-link-freetext" href="http://lists.cairographics.org/mailman/listinfo/cairo">http://lists.cairographics.org/mailman/listinfo/cairo</a>
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
</body>
</html>