473,809 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Transparent PNG and PIL

I am trying to create a simple script that Opens an existing PNG and
resaves it with a transparent color. With the command line version of
ImageMagic this is an easy endevor (and my current solution). I can
simply do something like:

convert -transparent black image.png image-transparent.png

(That makes anything black transparent in the saved image.)

It would seem that using PIL would make this simmilarly simple, but so
far I have not found a simple clear explanation of how to do this. If
someone has figured this out could you post it for the benefit of
mankind. ;)

On a somewat off topic matter (as far as Python goes), I see that
transparent PNGs, as created by tools such as image magic, do not
display transparent on MS Internet Explorer. I know that this is
probably because of MS's draggin their feet on supporting standards.
But, I noticed that with tools such as PaintShop Pro I can add
transparency to a PNG, and have it show correctly in IE. Does it do
this by in effect creating a proprietary PNG format?

When adding transparency to the PNG file, PaintShop says that the
image needs to be reduced to a single, paletted, background layer. It
then decreases the color depth to 256 colors. And then allows one to
set a color as transparent. When saving the image it warns that no
alpha channel will be saved. Nevertheless, the transparency is saved
correctly and displays correctly on all the tools I've tried. Can
someone shed a little light on what is going on here?
Jul 18 '05 #1
4 11693
R.Marquez wrote:
It would seem that using PIL would make this simmilarly simple, but so
far I have not found a simple clear explanation of how to do this. If
someone has figured this out could you post it for the benefit of
mankind. ;)
if you have an 8-bit palette image (mode "P"), you can specify the
transparency color (as a color index) when you save the image:

im.save(filenam e, transparency=0)

for RGB images, you can use the putalpha methods to add a transparency
layer to the image (turning into a mode "RGBA" image).
Does it do this by in effect creating a proprietary PNG format?


iirc, IE supports transparency masks for 8-bit palette images (mode "P"),
but it does not support transparency with true color images ("RGBA").

unless you use IE-specific filters, that is:

http://webfx.eae.net/dhtml/pngbehavior/pngbehavior.html

</F>


Jul 18 '05 #2
"Fredrik Lundh" wrote:
if you have an 8-bit palette image (mode "P"), you can specify the
transparency color (as a color index) when you save the image:

im.save(filenam e, transparency=0)


Not quite so simple. I tried this:
image = Image.open("Som e.png") #This file has transparency set correctly. image.mode 'P' image.info {'transparency' : 0} image.save("Som eT.png", trasparency=0)

When I open the new image with Paintshop it seems to think that the
image has trasparency set, but when I request to see it, nothing is
shown. What is more, when I open the image with PIL I see this:
image2 = Image.open("Tes t.png")
image2.mode 'P' image2.info

{}

So it seems to have lost the transparency.

The PIL handbook doesn't mention transparency as an option of the save
method for PNG files. It only mentions that the open method sets the
transparency info property for transparent palette images.
Jul 18 '05 #3
"R.Marquez" wrote:
image.info {'transparency' : 0} image.save("Som eT.png", trasparency=0)


"transparen cy", not "trasparenc y".

(the PNG writer ignores unknown configuration options)

</F>


Jul 18 '05 #4
"Fredrik Lundh" wrote:
"transparen cy", not "trasparenc y".


Oh. I forgot that Python is not only case sensitive but spell
sensitive as well. :o) Thank you.

-Ruben
Jul 18 '05 #5

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

Similar topics

1
20185
by: Efkas | last post by:
My application have some level : 1. MyButton class with Label inheritance 2. MyComponent as User Control loading and positionning some of MyButtons 3. MyApp loading and positionning MyComponent I prefer don't insert a background in MyComponent, and using the MyApp one as general background with MyComponent positionned, but I am not able to have MyComponent background transparent.
3
3109
by: Steve Koon | last post by:
Any thoughts on getting this project to work or suggesting another method would be appreciated. Steve ========================================== Project: A Windows Form which acts as a Whiteboard. The Form contains 3
7
3593
by: Peter Oliphant | last post by:
Using MakeTransparent one can supposedly turn a color used in a Bitmap to transparent. But, it looks to me like all it does it set these pixels to the color BackColor of the Control it's attached to. Thus, when I set White to the transparent color of a Bitmap stored in the Image of a PictureBox and placed the PictureBox on a Form which has a BackColor of black, it turned the white pixels of the bitmap image to black, but these black pixels...
5
6465
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...
8
10612
by: Grahammer | last post by:
Is it possible to set the background of a usercontrol as transparent? I tried setting the background image of the usercontrol to a transparent GIF, but that caused MAJOR problems. I'm making some controls that aren't rectangular and it won't be pretty if I end up with a grey rectangle behind each one. http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskGivingYourControlTransparentBackground.asp?frame=true
4
2566
by: jcrouse | last post by:
I am using the following code to move a label on a form at runtime: If myMousedown = lblP1JoyRight.Name Then If lblP1JoyRight.BackColor.Equals(Color.Transparent) Then bTransCk = True lblP1JoyRight.BackColor = clrLabelMove
2
3663
by: Pascal | last post by:
Je veux que mes label soit transparent aussi sur mes picturebox alors j'écris : i want my labels to be transparent on my pictureboxes so i wrote : Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Label1.Parent = PictureBox1 Label1.BackColor = Color.Transparent Label2.Parent = PictureBox2 Label2.BackColor = Color.Transparent
4
9378
by: ray well | last post by:
in my app i need to make a RichTextbox control transparent. i need it to be a like a pane of glass lying on a sheet of paper, where u can see everything on the sheet of paper not covered by text written on the glass pane. i need to be able to see the control or form that is underneath the RichTextbox, and at the same time to be able to write and erase text to the RichTextbox. i'm assuming that it is the backcolor that hides what is...
4
10251
by: Dale | last post by:
I am creating GIF images with transparent backgrounds on-the-fly for a web app and rendering them by using System.Drawing.Image.Save(Response.OutputStream, ImageType.GIF). I am confident that the transparency is working properly because if I save the created image to the local hard disk and then view it in a web page or an image editor, the transparency is correct. I can also view the transparency on-the-fly in a Windows.Forms...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
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
10376
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
10114
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...
1
7651
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
6880
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
5548
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...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.