[cairo-commit] [cairo-www] src/pythoncairopil.mdwn

Carl Worth cworth at freedesktop.org
Wed Sep 19 06:24:07 PDT 2007


 src/pythoncairopil.mdwn |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

New commits:
commit d7397a99b3de95c78c22b39222ab5a8b92ac1d57
Author: Carl Worth <cworth at annarchy.freedesktop.org>
Date:   Wed Sep 19 06:24:07 2007 -0700

    web commit by gerdusvanzyl: PIL usage with PyCairo

diff --git a/src/pythoncairopil.mdwn b/src/pythoncairopil.mdwn
new file mode 100644
index 0000000..5da66bd
--- /dev/null
+++ b/src/pythoncairopil.mdwn
@@ -0,0 +1,19 @@
+#PIL and Cairographics / PyCairo
+
+Please note that the code below was to only blur an cairo image surface and thus ignores conversion from BGRA to RGBA to BGRA that is needed in other situations. Theoretically just replace RGBA with BGRA in frombuffer and tostring.
+
+    im = cairo.ImageSurface.create_from_png("img11.png")
+            
+    im1 = Image.frombuffer("RGBA",( im.get_width(),im.get_height() ),im.get_data(),"raw","RGBA",0,1)
+            
+    im1 = im1.filter(ImageFilter.BLUR)
+    im1 = im1.filter(ImageFilter.BLUR)
+    im1 = im1.filter(ImageFilter.SMOOTH_MORE) 
+            
+    #imgd = im1.tostring("raw","RGBA",0,1)
+    imgd = im1.tostring()
+    a = array('B',imgd)
+            
+    stride = self.width * 4
+    surface = cairo.ImageSurface.create_for_data (a, cairo.FORMAT_ARGB32,
+                                                  self.width, self.height, stride) 
\ No newline at end of file


More information about the cairo-commit mailing list