[Image-SIG] How to convert mode 'RGB' into 'P'

Chris Cogdon chris at cogdon.org
Fri Oct 10 11:55:54 EDT 2003


On Friday, Oct 10, 2003, at 06:06 US/Pacific, Bjoern Platzen wrote:

> I tried outimg.convert('P') but it had no effect. The image was still 
> in
> 'RGB'-Mode.
>
> Is there anyway to do this? I think my images will become smaller when
> they are in mode 'P'.
-- 
    ("`-/")_.-'"``-._        Chris Cogdon <chris at cogdon.org>
     . . `; -._    )-;-,_`)
    (v_,)'  _  )`-.\  ``-'
   _.- _..-_/ / ((.'
((,.-'   ((,/   fL
When you convert to 'P' mode, you need to specify a palette. For 
example:

p_image = rgb_image.convert ( "P", palette=Image.ADAPTIVE, 
dither=Image.NONE, colors=256 )

If you want to ensure you're using the same palette as the original 'P' 
image, you can do this:

p_image = rgb_image.convert ( "P", palette=old_p_image.palette, 
dither=Image.NONE )


And, remember that 'convert' returns a new image, rather than affecting 
the object.

Hope that helps.



-- 
    ("`-/")_.-'"``-._        Ch'marr, a.k.a.
     . . `; -._    )-;-,_`)  Chris Cogdon <chmarr at furry.org.au>
    (v_,)'  _  )`-.\  ``-'
   _.- _..-_/ / ((.'       FC1.3: 
FFH3cmA+>++C++D++H++M++P++R++T+++WZ++Sm++
((,.-'   ((,/   fL               RLCT acl+++d++e+f+++h++i++++jp-sm++




More information about the Image-SIG mailing list