[PYTHON IMAGE-SIG] Should this work?

Fredrik Lundh fredrik.lundh@image.combitech.se
Fri, 23 May 1997 10:51:29 +0200

>    out = Image.new(img.mode,img.size)
>    out.fromstring(img.tostring())
> Since Magick and PIL images have similar interfaces this should
> work for both.  When I try to do this with a PIL image of mode 'P', 
> it breaks.  Is there a way to force a PIL image into 'RGB' mode
> before conversion?

The fromstring/tostring methods simply ignore the palette, and in
0.2b4, there's no clean way to attach a palette to an image.  So the
quickest solution is probably to convert the image:

	if im.mode == "P":
	    im = im.convert()

(convert without an argument converts to the palette mode, or copies
the image if it isn't a palette image in the first place).

I'm working on better palette support for 0.2b5 (still not sure if/how
palettes should be handled by tostring/fromstring, though).  You may
also wish to take a look at the palette patches Anthony Baxter sent to
this list a while ago.

Cheers	/F (http://hem1.passagen.se/eff)

IMAGE-SIG - SIG on Image Processing with Python

send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org