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

Mike C. Fletcher mcfletch at rogers.com
Sun Dec 14 09:39:09 EST 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 = Image.open(test.png)
>    fp = open('test.jpg','wb')
>    im.save(fp,'JPEG')
>  
>
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 = Image.open( r'p:\OpenGLContext\tests\wrls\simple_texturergba.png' )
 >>> alpha = i.getdata( 3 )
 >>> i2 = Image.new( 'L', i.size, )
 >>> i2.putdata( alpha )
 >>> i2.save( r'p:\OpenGLContext\tests\wrls\simple_texturea.jpg', 'jpeg' )

HTH,
Mike

_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/








More information about the Python-list mailing list