473,473 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

hi,

May anyone help me?

I need a lib which support .jpeg file with RGBA mode. PIL seems to support
RGB and CMYK mode only...

Thanks for your help.
Jul 18 '05 #1
7 5063
"google12" wrote:
May anyone help me?

I need a lib which support .jpeg file with RGBA mode. PIL seems to support
RGB and CMYK mode only...


last time I checked, JPEG didn't support RGBA.

</F>


Jul 18 '05 #2
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')

"Fredrik Lundh" <fr*****@pythonware.com> ¦b¶l¥ó
news:ma*************************************@pytho n.org ¤¤¼¶¼g...
"google12" wrote:
May anyone help me?

I need a lib which support .jpeg file with RGBA mode. PIL seems to support RGB and CMYK mode only...


last time I checked, JPEG didn't support RGBA.

</F>

Jul 18 '05 #3
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.p ng' )
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/


Jul 18 '05 #4
Ann... I had tried to use Photoshop 7 to save a .png file with transparency
as a .jpg file, and the transparency will be kept in the .jpg file.

Thus, I don't know why...

Thanks for your help.
"Mike C. Fletcher" <mc******@rogers.com> ???
news:ma*************************************@pytho n.org ???...
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.p ng' ) >>> alpha = i.getdata( 3 )
>>> i2 = Image.new( 'L', i.size, )
>>> i2.putdata( alpha )
>>> i2.save( r'p:\OpenGLContext\tests\wrls\simple_texturea.jpg' , 'jpeg' )

Jul 18 '05 #5
google12 wrote:

Ann... I had tried to use Photoshop 7 to save a .png file with transparency
as a .jpg file, and the transparency will be kept in the .jpg file.


If JPEG doesn't support transparency, then clearly that couldn't have happened,
or Photoshop uses a non-standard JPEG format.

Perhaps Photoshop "transparently" (no pun intended) saves the alpha data
to some other location, but magically restores it when you reload the .jpg?

(How have you confirmed that the data is really stored in the .jpg file
and not somewhere else?)
Jul 18 '05 #6
Peter Hansen <pe***@engcorp.com> wrote in message news:<3F***************@engcorp.com>...
...
Perhaps Photoshop "transparently" (no pun intended) saves the alpha data
to some other location, but magically restores it when you reload the .jpg?


That pun was _clearly_ intentional.
Jul 18 '05 #7
Peter Hansen wrote:
google12 wrote:

Ann... I had tried to use Photoshop 7 to save a .png file with transparency
as a .jpg file, and the transparency will be kept in the .jpg file.


If JPEG doesn't support transparency, then clearly that couldn't have happened,
or Photoshop uses a non-standard JPEG format.

Perhaps Photoshop "transparently" (no pun intended) saves the alpha data
to some other location, but magically restores it when you reload the .jpg?


JPEG supports application-defined data segments ("app markers"), so Photoshop
may simply pack the alpha layer using a suitable lossless compression (predictor
plus zip?) and embed it inside the JPEG stream.

or they may ignore that fact that using lossy compression for alpha layers isn't
really a good idea...

if anyone can mail me a sample (or better, post a sample somewhere, and mail
me an URL), I can look into it.

</F>


Jul 18 '05 #8

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

Similar topics

4
by: R.Marquez | last post by:
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...
6
by: rzed | last post by:
I'm using PIL to generate some images which may be rotated at the user's option. When they are rotated, the original image is cropped in the new image (which is fine), and the corners are black...
30
by: JKop | last post by:
When you want to store an integer in C++, you use an integral type, eg. int main() { unsigned char amount_legs_dog = 4; } In writing portable C++ code, there should be only two factors that...
1
by: James Hu | last post by:
Hi, I have png file with mode "I", 16 bit, And I tried to open it with im=Image.open("output.png"), im.show() I got all white image. Don't why? Can Image only support 'RGB' or 'RGBA' png...
11
by: aljosa | last post by:
i'm looking for image lib which supports common image types (maybe freeimagepy?) and is relatively easy to display image loaded through that lib in PyQt4. any ideas? Aljosa
1
by: Allard Warrink | last post by:
I would like to create a transparency gradient over an image using PIL. But I don't have a clue how to do this... Is there anyone out here who could give me some advise?
1
by: Lawrence D'Oliveiro | last post by:
I'm trying to create PNG files to use in menus for authoring DVDs. As you may know, these menus are only allowed to have limited numbers of colours. Ideally I'd like to create a PNG file with...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.