|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
transparency in palette mode ( "P" ) imagesDear list,
I have PNG image in palette mode, with 256 color palette. Every color has different level of transparency. For example: Color Table (RGB with 256 entries) 0: 0,0,0,0 1: 238,238,238,154 2: 253,253,109,154 3: 0,0,0,2 4: 0,0,0,4 5: 0,0,0,8 6: 0,0,0,6 7: 237,237,237,154 8: 0,0,0,14 9: 35,35,15,153 10: 1,1,0,138 I am trying just to open and save this image using PIL. #!/usr/bin/python import Image im = Image.open('test.png') im.save('out.png', transparency=0 ) After running this code, the resulting image is loosing transparency information for each color and it is set to 255. Color Table (RGB with 256 entries) 0: 0,0,0,0 1: 238,238,238,255 2: 253,253,109,255 3: 0,0,0,255 4: 0,0,0,255 5: 0,0,0,255 6: 0,0,0,255 7: 237,237,237,255 8: 0,0,0,255 9: 35,35,15,255 10: 1,1,0,255 Is there any way how to save the image with exactly same palette as original image ? For anybody wanting to look at this problem, You can download my test image here: http://gista.sk/dl/test.png Thanks, Ivan _______________________________________________ Image-SIG maillist - Image-SIG@... http://mail.python.org/mailman/listinfo/image-sig |
|
|
|
|
|
Re: transparency in palette mode ( "P" ) imagesHm.. you seem to be right. One thing you might do is im =
Image.open("test.png").convert("RGBA") which seems to solve the transparency problem, at the expense of a slightly larger image file. Looking closer I think that PIL seems to support only RGB palettes rather than RGBA palettes as does the PNG specification. Converting to RGBA would make editing work as expected, and would preserve all transparency information. If you just need to move/rename the image, try shutil.copy in the standard library. Edward On Tue, Oct 20, 2009 at 9:53 AM, Ivan Mincik <ivan.mincik@...> wrote: > On Tuesday 20 October 2009, you wrote: >> The problem seems to be that you set transparency=0 in your save. >> Leave it out ( im.save("out.png") ) and you should be fine. > > Many thanks for reply, but I think You are not right. If I save without 'transparency=0' I will loose my transparent background at all - it will be black. With 'transparency=0' I loose only transparency of my drawing, backround is OK. > My test image is here: http://gista.sk/dl/test.png > > >> If you just need to change the name try shutil.copy in the standard library. >> >> On Mon, Oct 19, 2009 at 2:05 PM, Ivan Mincik <ivan.mincik@...> wrote: >> > Dear list, >> > I have PNG image in palette mode, with 256 color palette. Every color >> > has different level of transparency. >> > For example: >> > Color Table (RGB with 256 entries) >> > 0: 0,0,0,0 >> > 1: 238,238,238,154 >> > 2: 253,253,109,154 >> > 3: 0,0,0,2 >> > 4: 0,0,0,4 >> > 5: 0,0,0,8 >> > 6: 0,0,0,6 >> > 7: 237,237,237,154 >> > 8: 0,0,0,14 >> > 9: 35,35,15,153 >> > 10: 1,1,0,138 >> > >> > I am trying just to open and save this image using PIL. >> > #!/usr/bin/python >> > import Image >> > >> > im = Image.open('test.png') >> > im.save('out.png', transparency=0 ) >> > >> > After running this code, the resulting image is loosing transparency >> > information for each color and it is set to 255. >> > Color Table (RGB with 256 entries) >> > 0: 0,0,0,0 >> > 1: 238,238,238,255 >> > 2: 253,253,109,255 >> > 3: 0,0,0,255 >> > 4: 0,0,0,255 >> > 5: 0,0,0,255 >> > 6: 0,0,0,255 >> > 7: 237,237,237,255 >> > 8: 0,0,0,255 >> > 9: 35,35,15,255 >> > 10: 1,1,0,255 >> > >> > Is there any way how to save the image with exactly same palette as >> > original image ? >> > >> > For anybody wanting to look at this problem, You can download my test >> > image here: >> > http://gista.sk/dl/test.png >> > >> > Thanks, >> > Ivan >> > _______________________________________________ >> > Image-SIG maillist - Image-SIG@... >> > http://mail.python.org/mailman/listinfo/image-sig >> > >> > > > > -- > Ivan Mincik > Gista s.r.o. > Image-SIG maillist - Image-SIG@... http://mail.python.org/mailman/listinfo/image-sig |
|
|
|
|
|
Re: transparency in palette mode ( "P" ) imagesOn Tue, Oct 20, 2009 at 8:33 PM, Laura & Edward Cannon
<cannon.el@...> wrote: > Hm.. you seem to be right. One thing you might do is im = > Image.open("test.png").convert("RGBA") which seems to solve the > transparency problem, at the expense of a slightly larger image file. No, even if using convert("RGBA") I get incorrect result :( > Looking closer I think that PIL seems to support only RGB palettes > rather than RGBA palettes as does the PNG specification. Converting to > RGBA would make editing work as expected, and would preserve all > transparency information. If you just need to move/rename the image, > try shutil.copy in the standard library. > Edward > > On Tue, Oct 20, 2009 at 9:53 AM, Ivan Mincik <ivan.mincik@...> wrote: >> On Tuesday 20 October 2009, you wrote: >>> The problem seems to be that you set transparency=0 in your save. >>> Leave it out ( im.save("out.png") ) and you should be fine. >> >> Many thanks for reply, but I think You are not right. If I save without 'transparency=0' I will loose my transparent background at all - it will be black. With 'transparency=0' I loose only transparency of my drawing, backround is OK. >> My test image is here: http://gista.sk/dl/test.png >> >> >>> If you just need to change the name try shutil.copy in the standard library. >>> >>> On Mon, Oct 19, 2009 at 2:05 PM, Ivan Mincik <ivan.mincik@...> wrote: >>> > Dear list, >>> > I have PNG image in palette mode, with 256 color palette. Every color >>> > has different level of transparency. >>> > For example: >>> > Color Table (RGB with 256 entries) >>> > 0: 0,0,0,0 >>> > 1: 238,238,238,154 >>> > 2: 253,253,109,154 >>> > 3: 0,0,0,2 >>> > 4: 0,0,0,4 >>> > 5: 0,0,0,8 >>> > 6: 0,0,0,6 >>> > 7: 237,237,237,154 >>> > 8: 0,0,0,14 >>> > 9: 35,35,15,153 >>> > 10: 1,1,0,138 >>> > >>> > I am trying just to open and save this image using PIL. >>> > #!/usr/bin/python >>> > import Image >>> > >>> > im = Image.open('test.png') >>> > im.save('out.png', transparency=0 ) >>> > >>> > After running this code, the resulting image is loosing transparency >>> > information for each color and it is set to 255. >>> > Color Table (RGB with 256 entries) >>> > 0: 0,0,0,0 >>> > 1: 238,238,238,255 >>> > 2: 253,253,109,255 >>> > 3: 0,0,0,255 >>> > 4: 0,0,0,255 >>> > 5: 0,0,0,255 >>> > 6: 0,0,0,255 >>> > 7: 237,237,237,255 >>> > 8: 0,0,0,255 >>> > 9: 35,35,15,255 >>> > 10: 1,1,0,255 >>> > >>> > Is there any way how to save the image with exactly same palette as >>> > original image ? >>> > >>> > For anybody wanting to look at this problem, You can download my test >>> > image here: >>> > http://gista.sk/dl/test.png >>> > >>> > Thanks, >>> > Ivan >>> > _______________________________________________ >>> > Image-SIG maillist - Image-SIG@... >>> > http://mail.python.org/mailman/listinfo/image-sig >>> > >>> >> >> >> >> -- >> Ivan Mincik >> Gista s.r.o. >> > Image-SIG maillist - Image-SIG@... http://mail.python.org/mailman/listinfo/image-sig |
|
|
Re: transparency in palette mode ( "P" ) imagesOn Tue, Oct 20, 2009 at 4:51 PM, Ivan Mincik <ivan.mincik@...> wrote:
> > On Tue, Oct 20, 2009 at 8:33 PM, Laura & Edward Cannon > <cannon.el@...> wrote: > > Hm.. you seem to be right. One thing you might do is im = > > Image.open("test.png").convert("RGBA") which seems to solve the > > transparency problem, at the expense of a slightly larger image file. > > No, even if using convert("RGBA") I get incorrect result :( Maybe the problem is in the decoder. Can't you use a PNG in RGBA mode instead of P mode? If it is a bug, you have to do a workaround before or after you open the PNG with PIL. _______________________________________________ Image-SIG maillist - Image-SIG@... http://mail.python.org/mailman/listinfo/image-sig |
|
|
Re: transparency in palette mode ( "P" ) imagesOn Tue, Oct 20, 2009 at 9:02 PM, David Kwast <david.kwast@...> wrote:
> On Tue, Oct 20, 2009 at 4:51 PM, Ivan Mincik <ivan.mincik@...> wrote: >> >> On Tue, Oct 20, 2009 at 8:33 PM, Laura & Edward Cannon >> <cannon.el@...> wrote: >> > Hm.. you seem to be right. One thing you might do is im = >> > Image.open("test.png").convert("RGBA") which seems to solve the >> > transparency problem, at the expense of a slightly larger image file. >> >> No, even if using convert("RGBA") I get incorrect result :( > > Maybe the problem is in the decoder. Can't you use a PNG in RGBA mode > instead of P mode? No, I need to process images in P mode and have resulting image also in P mode. If it is a bug, you have to do a workaround before or > after you open the PNG with PIL. I do not see possibility of any workaround. Converting to RGBA does not help. _______________________________________________ Image-SIG maillist - Image-SIG@... http://mail.python.org/mailman/listinfo/image-sig |
| Free embeddable forum powered by Nabble | Forum Help |