473,786 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PIL and transparent GIFs

Hi,

Does anybody know how to save an image in GIF format preserving transparent
background ??

Here's what I tested :

import Image, ImageDraw
im = Image.open('/path/to/model.gif') # An image with transparent backgroung
draw = ImageDraw.Draw( im)
draw.polygon([153,106,186,225 ,340,193,315,81 ,304,167], fill=9587)
im.save('/path/to/model1.gif', 'GIF')

And model1.gif has no transparent background anymore even if it's bigger
than my polygon selection.

Regards,

Laurent.
Feb 1 '06 #1
3 4278
It can only read transparency, it can't write it. I went looking and
found that out a couple weeks ago.

Feb 1 '06 #2
On 1 Feb 2006 14:41:05 -0800
"Kamilche" <kl*******@comc ast.net> wrote:
It can only read transparency, it can't write it. I went
looking and found that out a couple weeks ago.


There was a patch published at one time that was supposed
to fix this. I remember doing some testing and not finding
it to work perfectly, but I may have been doing something
wrong. Can't recover it at the moment, but some search
engine work might turn it up.

--
Terry Hancock (ha*****@Anansi Spaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com

Feb 2 '06 #3
Terry Hancock wrote:
There was a patch published at one time that was supposed
to fix this. I remember doing some testing and not finding
it to work perfectly, but I may have been doing something
wrong. Can't recover it at the moment, but some search
engine work might turn it up.


transparency write support was added in 2002.

however, PIL's Image object doesn't have a notion of "transparen t
color index", so you have to keep track of it yourself.

im = Image.open(...)
transparency = im.info["transparen cy"]
...
out.save("out.g if", transparency=tr ansparency)

</F>

Feb 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7531
by: Jim | last post by:
Now this is just weird. And yes, I validated the html and the stylesheet. I created a transparent gif image in Paint Shop Pro 7. I made the mistake of making a transparent png and went along merrily until I viewed the pages (it's a multi-page three and two column site with an underlying stylesheet) in IE6. The transparent png worked fine in Mozilla but broke IE6. Sooooo, I recreate the image as a gif and it seems to work just fine in both...
8
6491
by: djmanmaster | last post by:
Am I right in thinking that images with transparent areas (GIFs or PNGs) should allow clicks to "pass through" to any underlying elements behind them? I have had no luck getting this to work in IE or Firefox. I have tried GIF and PNG with 'binary' transparency and PNG24 with 'alpha' transparency (obviously the latter won't work in IE without the AlphaImageLoader trick). Here is a test page for you to see it not working in action:
1
13142
by: Chris Auer | last post by:
I have been banging my head for a couple of hours now. No matter what I do the color that I make transparent is black. Here is the code I am using from MSDN. I have tried bitmaps, jpegs, gifs and new bitmaps created in code, but I cant get any image to go transparent. Thanks if you can help. // Create a Bitmap object from an image file. Bitmap myBitmap = new Bitmap(System.Web.HttpContext.Current.Server.MapPath("resources/img/")
1
1880
by: Chris Tremblay | last post by:
I am trying to create an image using GDI+ in VB.NET. I want to have the background be transparent, but when I do run the following: myGraphicsObject.clear(color.transparent) the resulting background color is black, not transparent. I am saving the image to the output stream as an "image/gif". Is there anything I should know about this, any reason that the result would be black? --
4
2039
by: tshad | last post by:
I have some transarent gifs (actually PNG files) that are not working in IE. They work fine in Netscape and Mozilla. In IE the following shows a grey border around the figure (which should be transparent. <asp:ImageButton ID="ExpandButton" runat="server" Font-Size="2" ImageUrl="../images/expand.jpg" Width="16" Height="16" CommandName="Select" AlternateText="Click here to see details"></asp:ImageButton> When I change it to:
5
6462
by: Mark Deibert | last post by:
I'm a former VB6 coder. Quit a few years ago. Now I'm back and trying to teach myself VB.NET. I don't remember having this much difficulty learning VB6. I'm totally stuck on something and need your expert guidance. I just want to load a GIF with a transparent background into a container with a transparent background. So I can move the GIFs over and under each other. You know, as in basic game stuff. I can load the transparent GIF no...
9
5034
by: RCS | last post by:
I'm working on an ASP.NET webpage that generates an image (and am using VWD 2005 until my copy of VS2005 ships). I have done all the obvious (and not-so-obvious) things to try to give a gif that I am generating, a transparent background. On the newsgroups - everyone points to this MSDN article: How to save a .gif file with a new color table by using Visual C# .NET http://support.microsoft.com/default.aspx?scid=kb;en-us;319061 Even...
2
2719
by: Trond Michelsen | last post by:
Hi. I have a transparent PNG-image that I would like to display on top of the rest of the web page. I've already got this part working. But, I'd like the background (as in "the part of the image that is transparent"), to be semi transparent instead. So, I've wrapped the image in a div-tag with the style "opacity: .70" instead. This gives me pretty much the semi transparency that I'm looking for, except that this makes the entire image...
5
23920
by: Dale | last post by:
When I create a System.Drawing.Bitmap and save it as ImageType.GIF, how can I set the transparency so that the background is transparent. In my application, the Bitmap that I am working with has several transparent GIFs drawn on it and the transparency of each of them works within the bitmap, but the bitmap overall gets saved with a black background. Any help is greatly appreciated.
8
3023
by: salmobytes | last post by:
Making thumbnail images isn't all that hard, for the most part. There is lots of shrink-wrapped code out there you can download and/or munge from. But nothing I've yet seen does the right thing with transparent background gifs. If you (I) try to work with ImageCreateFromGif($this->path); you end up with a black background. Does anybody know how to make transparent background gif thumbnails? Or maybe how to at least turn the background
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.