[PYTHON IMAGE-SIG] Transparent GIF images & Tk
Fred L. Drake
fdrake@CNRI.Reston.Va.US
Mon, 30 Dec 1996 12:41:13 -0500 (EST)
> A reasonable attempt, but the color parameter gets lost on its way
> down to the C code. Joel Shprentz reported this out a while ago, but
> the fix didn't make it into the latest release (sorry, Joel). I'll
> try fixing it to the next release.
Hmm.... I couldn't quite figure out where the color value gets
lost, so I'll wait for your fix on that.
The subscript operator on the image objects defined in
_imagingmodule.c is broken: in the function image_item(), the line:
y = i / im->ysize;
should be changed to:
y = i / im->xsize;
With this change, I can sometimes get tolerable results with this
function:
def transp_gif_to_rgb(im, (r, g, b)):
"""Translate a P-mode GIF with transparency to an RGB image.
im
The GIF image.
(r, g, b)
The RGB-value to use for the transparent areas. These should be
8 bits for each band.
"""
# This is really quite slow.
bg = im.info["background"]
rgbimg = Image.new("RGB", im.size, (r<<24 | g <<16 | b<<8))
mask = Image.new("1", im.size)
drawing = ImageDraw.ImageDraw(mask)
getpixel = im.getpixel
point = drawing.point
yrange = range(im.size[1])
ylength = im.size[1]
for x in range(im.size[0]):
for pos in map(None, [x]*ylength, yrange):
if getpixel(pos) != bg:
point(pos)
rgbimg.paste(im, None, mask)
return rgbimg
-Fred
--
Fred L. Drake, Jr.
fdrake@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive
Reston, VA 20191-5434
=================
IMAGE-SIG - SIG on Image Processing with Python
send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org
=================