Is there a lib which support .jpeg file with "RGBA" mode?

Mike C. Fletcher mcfletch at
Sun Dec 14 15:39:09 CET 2003

google12 wrote:

>Oh, sorry. I made a mistake...
>My question is -- when I run the code described below, the transparence of
>the orginal image will be removed. How can I keep the transparence?
>    im =
>    fp = open('test.jpg','wb')
I believe the thrust of Fredrik's post was: you can't. JPEG does *not* 
store alpha channels.  It's just not part of the format, so if you need 
to store in JPEG format, you will not be storing the alpha channel in 
the file.

If what you're asking is whether you can store the alpha data to a 
separate file (as is done with programs such as 3DStudio Max), yes, that 
can be done too:

 >>> import Image
 >>> i = r'p:\OpenGLContext\tests\wrls\simple_texturergba.png' )
 >>> alpha = i.getdata( 3 )
 >>> i2 = 'L', i.size, )
 >>> i2.putdata( alpha )
 >>> r'p:\OpenGLContext\tests\wrls\simple_texturea.jpg', 'jpeg' )


  Mike C. Fletcher
  Designer, VR Plumber, Coder

More information about the Python-list mailing list