On Tue, 2005-08-30 at 21:16 -0700, Robert Kern wrote:
> Why not use PIL where it's available? backend_agg2.py has a start at
> this. Here's a slightly more fleshed-out (but untested) implementation
> for backend_agg.py :
>
> if not is_string_like(filename):
> try:
> import Image
> have_pil = True
> except ImportError:
> have_pil = False
> if have_pil:
> img = Image.frombuffer('RGBA', (self.width, self.height),
> self.buffer_rgba(0, 0))
> img.write(filename)
> else:
> self.renderer._renderer.write_png(filename)
I've previously had a problem with the origin when doing something
similar with buffer_rgba (resulting in a vertical flip). Doing:
im = Image.frombuffer('RGBA', (self.width, self.height),
self.buffer_rgba(0, 0),
'raw', 'RGBA', 0, 1)
fixes that problem.
If a method utilising PIL images in this manner is added I'd suggest
adding a to_pil (or similar) method for those who want to process the
resulting image in some manner requiring PIL.
Nick
|