[Image-SIG] Using PIL to change bitmaps - transparency masking?

Mark Daley 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
ReportLab.
 
Here is the line that's killing me:
 
 
proof.drawImage(out, int(values[2]), int(values[3]), 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[4])[0] + 'temp.bmp'
        print tempimage
        im = Image.open(values[4])
        print im.format, im.size, im.mode
        xval = im.size[0]
        yval = im.size[1]
        for horiz in range(xval):
             for vert in range(yval):
                  if im.getpixel((horiz, vert)) == 0:
                       im.putpixel((horiz, vert), 1)
                  else:
                       im.putpixel((horiz, vert), 0)
        out = im.rotate(180)
        proof.drawImage(out, int(values[2]), int(values[3]), mask =
[0,1,0,1,0,1])
        out.save(tempimage, 'BMP')
 

- Mark Daley

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/image-sig/attachments/20050218/2441c11e/attachment.html


More information about the Image-SIG mailing list