[cairo] High Quality ImagePattern Scaling

Andrew Ingram andrew.ingram at titanemail.com
Tue Aug 26 04:16:51 PDT 2008


Hi all,

Having explored other options i've come to try using pycairo to resize 
and rotate some png images. The problem i'm having is that no matter 
what options I specify, I can't seem to get the resized images to be of 
a high quality, the output is very pixelated even without rotating.

This is my algorithm:

image = cairo.ImageSurface.create_from_png(path)
   
# some mathsy calculations
   
pattern = cairo.SurfacePattern(image)
pattern.set_filter(cairo.FILTER_BEST)
   
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
context = cairo.Context(surface)
   
context.set_antialias(cairo.ANTIALIAS_SUBPIXEL)

context.rectangle (0,0,WIDTH,HEIGHT)
context.translate(H_SHIFT,V_SHIFT)
context.scale(scaleX,scaleY)  
context.rotate(math.radians(float(rotate)))

context.set_source(pattern)
context.fill()
   
output = cStringIO.StringIO()
surface.write_to_png(output)


I've tried using PIL to achieve this but the quality for rotations was 
very poor, cairo seems to do rotations to a reasonable quality but 
resizing is a different matter.

Regards,
Andrew Ingram

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


More information about the cairo mailing list