[Image-SIG] PIL Programming Questions
paul.prescod at xmetal.com
Sat Aug 19 01:26:50 CEST 2006
I just finished a PIL program and I feel like there may have been more
efficient ways to do things I did "by hand" with the raw data. Can
someone enlighten me?
1. I wanted to take 24 bit data, count the colours and make an 8-bit BMP
if there are fewer than 256 colours. My brute force solution required me
to build the palette by hand from the data and rewrite the data one
pixel at a time. (a simple '.convert("P")' seems to use an arbitrary
palette or something???)
2. I wanted to pad a bitmap by adding some space to the right and
bottom. I did this by creating a new one and pasting the old one into
3. I wanted to convert every occurrence of one colour to another. I
walked each pixel.
I also could not figure out how to get to a 4-bit BMP. I inferred from
the documentation that this just isn't possible with out of box PIL.
Overall: PIL really rocks.
More information about the Image-SIG