By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

PIL question

P: n/a
I'm trying to read an image with PIL, crop several subimages out of it,
and try to combine the subimages again into a combined new one. This is
a test script, later I want to only several single images into a combined one.

I have to work with 16-bit color windows bitmaps in BMP format.

My input image (input.bmp) IS a 16-color bmp. The cropped images that
the script saves are saved in 8-bit/256-color format; they look correct.
The combined image is also saved in 8-bit/256-color format, but it is
all black - maybe the palette is missing?

Anyway, I cannot use 256-color images. How do I save the images in 4-bit/16-color
format?

Thanks,
Thomas

Here is the code; I'm using Python 2.4 and PIL 1.5:

<code>
import Image
img = Image.open("input.bmp")

w, h = img.size
print img.size, img.mode

newimg = Image.new("P", (16*30, 15))

x = 0
i = 1
while x < w:
this = img.crop((x, 0, x+16, 15))
this.save("%02d.bmp" % i)
newimg.paste(this, (x, 0, x+16, 15))
x += 16
i += 1

newimg.save("output.bmp")

<code/>

Nov 16 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.