Initializing a 'P' image

Chris Barker <[email protected]> Tue, 19 Jun 2012 12:24:49 -0700
Newsgroups gmane.comp.python.image
Message-ID <CALGmxEKpyOv3BUhqeB+nx5RmsJ9J+h-47=MO_0ogGHpHEvDzVg@mail.gmail.com>
HI folks,

I'm creating, then drawing to, a "P" paletted image.

I like how ImageDraw will let you set the colors as you drawm and it
will automaticaly get added to teh palette.

However, I can't see how to initialize the image with a given
background (fill) color:

In [35]: Image.new('P', (10,10), color=(255,255,255))

TypeError: an integer is required

I can set color to 0  (Or, presumabley any other 8-bit integer), but
then there is no color added to the palette, so it will get whatever I
happend to draw first.

So I've ended up doing this:

        self.image = Image.new('P', size, color=0)
        drawer = ImageDraw.Draw(self.image) # couldn't find a better
way to initilize the colors right.
        drawer.rectangle(((0,0), size), fill=self.background_color)

but that sure feels kludgy -- have I missed something?

Of course, I could manage the palette myself, but that's uglier...

-Chris







-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]
_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig