[Image-SIG] Pasting images
Rob Myroon
robmyroon@yahoo.com
Thu, 9 Jan 2003 11:32:04 -0800 (PST)
I recently had similar transparency problems with .png files ...
In order to save a .png with transparency I modified PngImagePlugin.py.
I added these lines starting at line 427 in function _save()
if im.mode == "P":
chunk(fp, "PLTE", im.im.getpalette("RGB"))
# extra code starts here (this is line 427)
if not im.encoderinfo.has_key("transparency"):
if im.info.has_key("transparency"):
im.encoderinfo["transparency"] = im.info["transparency"]
# extra code ends here
if im.encoderinfo.has_key("transparency"):
if im.mode == "P":
This works for .pngs with mode "P". I didn't test it for mode "L". Just make sure the
'transparency' member of the image's info dict is set.
Rob
--- "Eric S. Raymond" <esr@snark.thyrsus.com> wrote:
> I'm confused by the behavior of the paste() method. I'm trying to
> paste a PNG image onto a background generated by Image,new().
>
> It appears to me from the manual that if flag.png is a 30x30 image,
> the following sequence of operations
>
> im = Image.new("P", (60, 60))
> flag = Image.open("flag.png")
> im.paste(flag, (15, 15))
>
> ought to leave the flag pasted onto the middle of a black background.
>
> It doesn't. All I see is black.
>
> PIL 1.1.3, Python 2.3a0, Red Hat 8.0.
>
> While we're att it, how do I generate a new image that is transparent?
> Or set a transparency color on an existing image? Setting the
> 'transparency' memeber of an image's info dict doesn't seem to do it.
>
> What am I doing wrong?
> --
> <a href="http://www.tuxedo.org/~esr/">Eric S. Raymond</a>
>
> As with the Christian religion, the worst advertisement for Socialism
> is its adherents.
> -- George Orwell
>
> _______________________________________________
> Image-SIG maillist - Image-SIG@python.org
> http://mail.python.org/mailman/listinfo/image-sig
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com