[Image-SIG] Using PIL to change bitmaps - transparency masking?
mark at diversiform.com
Fri Feb 18 17:47:45 CET 2005
I am trying to use the Image module to do some bitmap conversions (pretty
simple, just invert, rotate and set transparency) and write to a PDF through
Here is the line that's killing me:
proof.drawImage(out, int(values), int(values), mask = [0,1,0,1,0,1])
Now, in a bitmap, you have two color options, 0 and 1. I have determined
that 0 is white and 1 is black. However, when I use the mask option to
attempt to mask the white in the bitmap when I write it to the PDF, it ends
up masking the black pixels. Well, no problem, I think, I'll just mask the
opposite choice. Wrong! Whether I change the mask to [1,2,1,2,1,2] or
[255,256,255,256,255,256], nothing happens. Is what I'm trying to do even
possible? I have posted the snippet below for your perusal.
tempimage = os.path.splitext(values) + 'temp.bmp'
im = Image.open(values)
print im.format, im.size, im.mode
xval = im.size
yval = im.size
for horiz in range(xval):
for vert in range(yval):
if im.getpixel((horiz, vert)) == 0:
im.putpixel((horiz, vert), 1)
im.putpixel((horiz, vert), 0)
out = im.rotate(180)
proof.drawImage(out, int(values), int(values), mask =
- Mark Daley
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Image-SIG