Transparency color when converting ICO -> PNG

Ask for help and post your question on how to use XnView Classic.

Moderators: XnTriq, xnview

Post Reply
User avatar
dma_k
Posts: 79
Joined: Tue Apr 14, 2009 8:50 am

Transparency color when converting ICO -> PNG

Post by dma_k » Sat Aug 13, 2011 10:58 pm

Dear community,

I feel like I can't understand how to correctly convert from ICO to PNG/GIF, preserving the transparency.

I hope that ICO supports transparency, as some of the topics from here and here give different view on the problem.

So as input I've got ICO file, which I would like to convert to GIF or PNG with preserving the transparency. First what I've noticed, is that the small images on tab do not display the transparency correctly:

Image

The image is also shown like that when I do the export. I tried to set different colors with "Set transparency" with no positive result.

How should I do this operation in right way?

The original file is called favicon.ico in test.zip, the resulting conversion to PNG is favicon_actual.png, while I would expect something like favicon_expected.png.

XnView 1.98.2.

User avatar
XnTriq
Moderator & Librarian
Posts: 5431
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Transparency color when converting ICO -> PNG

Post by XnTriq » Sat Aug 13, 2011 11:45 pm

Hello dma_k =)

“Set the transparency value to palette entry” in Tools » Options... » General » Read/Write » Write » GIF/PNG only works for images with indexed color (< 24-bit).

Since favicon.ico has a color depth of 32 bits per pixel, you need to save it via File » Export... as PNG and set the Color mode to 16m in order to preserve the alpha-channel transparency.

User avatar
dma_k
Posts: 79
Joined: Tue Apr 14, 2009 8:50 am

Re: Transparency color when converting ICO -> PNG

Post by dma_k » Sun Aug 14, 2011 1:21 am

Hi XnTriq,

I got the situation with PNG... Pity that xnview does not warn, that the selected depth does not allow the transparency :(

Anyway, I was not able to do the same trick with GIF: whatever color depth I choose I get the ugly black background. Maybe you can help me with it?

User avatar
Drahken
Posts: 884
Joined: Sun Apr 10, 2005 4:29 pm

Re: Transparency color when converting ICO -> PNG

Post by Drahken » Sun Aug 14, 2011 2:53 am

1) You shouldn't -have- to use the export thing with PNG. As long as the image is in 32bit mode when you save it (the statusbar should say "16x16x32") it should save the PNG with the alpha channel intact (it did for me).

2) GIF is locked to 8bit color, the only transparency it supports is single color transparency. This is a weakness inherant in the format itself (and one of the reasons why GIF should be avoided when possible).
The only way to get it usable as a gif is to first convert it to a 32bit PNG, then open that PNG and convert it to fewer colors (8 colors worked fine for me).
Go to tools->options->read/write->"read" tab->PNG, and make sure the "compose with alpha" box is checked.
Open the PNG, click image->convert to colors and convert it to 8 colors. Then click image->edit palette, then select the white square & check the enable transparency box.
This will leave you with light "jaggies" all around the image, but there's no other way. When using gif, you just have to cope with such jaggies.
Now save as gif (but click "options" on the save dialog & make sure the "set transparency to..." box is UNchecked, or that will overwrite the palette adjustment you already made).

Apparently xnview doesn't compose ICO files with alpha channels properly, which doesn't allow xnview to properly convert them to fewer colors without losing that data.




Here's the GIF I managed to create from your ICO file: http://allspark.net/cypherswipe/dmak-favicon.gif
Oh the feuhrer, oh the feuhrer, oh the feuhrer's nipples bonk!

User avatar
dma_k
Posts: 79
Joined: Tue Apr 14, 2009 8:50 am

Re: Transparency color when converting ICO -> PNG

Post by dma_k » Sun Aug 14, 2011 1:03 pm

Thanks for your hint! It was really not obvious how to do it. Finally it worked as you advised: I have opened the ICO, "saved as" PNG, opened PNG and now export dialog looks better...

However, I think that is bug in xnview that it cannot handle ICO files correctly. Because conversion to PNG smashes the image and export dialog looks strange. Also when "converting to colors..." (or "remove alpha channel") the transparency information is lost in an unexpected way to say so.

Image

The only thing which helps is "True colour" (and then "Export") and perhaps that is most fast way.

User avatar
Drahken
Posts: 884
Joined: Sun Apr 10, 2005 4:29 pm

Re: Transparency color when converting ICO -> PNG

Post by Drahken » Sun Aug 14, 2011 9:23 pm

Yeah, xnview could definitely use better handling of ICO files with alpha channels. (The problem is that only PNGs have the option to "compose with alpha", which is the function that makes them behave properly.) However, I wonder how many people actually use xnview to work with ICO files at all, let alone 32bit ones?

I managed to get a clean gif version (with no jaggies) by using greenfish icon editor to convert the original icon, but it can't get a decent png from it (it only exports to 24bit png, with no transparency at all).

http://allspark.net/cypherswipe/favicon-test.gif
Oh the feuhrer, oh the feuhrer, oh the feuhrer's nipples bonk!

User avatar
XnTriq
Moderator & Librarian
Posts: 5431
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Transparency color when converting ICO -> PNG

Post by XnTriq » Mon Aug 15, 2011 3:00 am

  • Image 32-bit (16m truecolor + alpha channel) PNG
    vs. Image 2-bit (4 color palette) GIF
@Pierre: Is it possible to implement a “matte” option for color depth reduction of RGBA images?

User avatar
XnTriq
Moderator & Librarian
Posts: 5431
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Transparency color when converting ICO -> PNG

Post by XnTriq » Wed Aug 17, 2011 7:00 pm

  1. Download and open Image favicon.ico.
  2. Reduce the color depth with Image » True Colour.
  3. Move the slider in Image » Map » Posterize... to 2 and click OK.
  4. Reduce the color depth to 8 with Image » Convert to Colours... (Dithering: None) and click Apply.
  5. Go to Image » Edit Palette... and double-click the third color (Index: 2).
  6. Change the value from R0/G255/B255 to R0/G170/B238 (see official style guide) in the color picker and click OK.
  7. Set Save as type in File » Save As... to GIF - CompuServe GIF.
  8. Go to Options in the Save As... dialog, Set the transparency value to palette entry 0 and click OK.
  9. Save Image superuser.com.gif.

User avatar
dma_k
Posts: 79
Joined: Tue Apr 14, 2009 8:50 am

Re: Transparency color when converting ICO -> PNG

Post by dma_k » Wed Nov 23, 2011 12:13 am

Another note from me:

It would be nice if "True Color" function uses the background colour to replace the transparent color. It seems like it always uses white color. If I can customize this color, that I can choose the color not in palette, which will simplify the "Set transparent" color later.

Post Reply