How to set PNG transparency color?

Frequently Asked Questions regarding XnView (including Answers)

Moderators: XnTriq, xnview

User avatar
JohnFredC
XnThusiast
Posts: 2010
Joined: Wed Mar 17, 2004 8:33 pm
Location: Sarasota Florida

How to set PNG transparency color?

Postby JohnFredC » Sun Mar 19, 2006 4:52 pm

I searched the forum but didn't find a clear answer to this:

In the PNG options there is a place to enter the palette "entry" for the transparency color.

If I want a specific color in my image to map to transparent (say, magenta), what value do I put in that PNG option?

Perhaps it would be good to display a palette in that dialog?
John

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

Postby XnTriq » Mon Mar 20, 2006 2:45 am

:) Hi JohnFredC!

If it's a true color image you'll have to reduce the color depth first.
To determine an index number, go to Image » Edit Colormap… (in View mode).
When you move the mouse cursor over a palette entry, the color's index number, its RGB value & the HTML/hex code are displayed in the list box on the right.

User avatar
JohnFredC
XnThusiast
Posts: 2010
Joined: Wed Mar 17, 2004 8:33 pm
Location: Sarasota Florida

Postby JohnFredC » Mon Mar 20, 2006 2:50 am

Thank you very much! I've never done that before.

And yes, I had to reduce the colors of the image. Didn't turn out too badly though... and the transparency worked!

Thanks again!
John

User avatar
helmut
Posts: 8116
Joined: Sun Oct 12, 2003 6:47 pm
Location: Frankfurt, Germany

Postby helmut » Mon Mar 20, 2006 9:26 pm

A while back I've written up an FAQ that describes the creation of images with transparency. The FAQ is not finished, yet, here a part which might be useful:

Step 4: Determine the transparent colour
In some images, the background colour is different to all the other colours and it's obvious which is the background colour. But in some images it might be not so obvious.

In this case you can use the colour info to determine the index of the background colour:

a) Select menu "View > Display Colour Information" The mouse cursor's shape will change to a pipette. Also next to the mouse cursor, the index, the RGB colour and Hex value of the colour will be displayed.
b.) Move the mouse cursor to an area fo your image which is the background.
c.) Now remember the index of the colour which ranges from 0..255

Step 5: Set the transparent colour
Now that you have reduced size and set reduced colour depth of your image, you finally set the transparent colour of your image.

For setting the transparent colour (assuming that XnView and your image are still open)

a.) Open the "Colour map" dialog using menu "Image > Edit colour map"
b.) Click onto the colour with the index that you have determined above in Step 3.).
c.) If you have used an odd colour (e.g. magenta) as background, double click onto the selected colour. Now you can change the colour of your transparent colour to whichever colour you like (actually it doesn't matter much, since the colour will be transparent in real life.).
d.) Set the checkbox "Use transparent colour"

Note:
Make sure you first perform b.) and then d.), otherwise the transparent colour will not be set properly.

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

Postby XnTriq » Sun Aug 20, 2006 10:40 pm

Last edited by XnTriq on Tue Apr 10, 2007 10:00 pm, edited 1 time in total.

OJG

See throught Background

Postby OJG » Fri Aug 25, 2006 4:35 am

Hi I am having a very hard time changing my background color fon my image from a green background to a "see through" background. Is it anybody that can help me with this

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

Postby Drahken » Fri Aug 25, 2006 10:41 am

Image->convert to colors (however many colors you want, adaptive is generally better than dithered)
Image->edit color map
Select the green square, then go over and check the little box that says transparency.
Click "ok", and the areas that were formerly green will now appear whatever background color is set in the program options (but it's actually transparent, just save the image and open it in your web browser to see.)

If you want to change the background color in the program, go tools->options->view and you'll see a box for background color. Keep in mind that this color is only used in the program, and has no effect on the images themselves.
Oh the feuhrer, oh the feuhrer, oh the feuhrer's nipples bonk!

User avatar
GeorgD
Posts: 258
Joined: Thu Oct 12, 2006 2:45 pm

Postby GeorgD » Sun Dec 03, 2006 12:26 am

I want to bring this topic up again, as IMHO the 1.90beta2 Export wizard shall be able to set the transparency (as checkbox "set transparency for palette entry 0" or - my varoured solution - by popping up the color palette and selecting the color that shall be transparent) when 256colors are selected from the drop down. Thoughts?

User avatar
xnview
Author of XnView
Posts: 27690
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Postby xnview » Mon Dec 04, 2006 12:03 pm

GeorgD wrote:I want to bring this topic up again, as IMHO the 1.90beta2 Export wizard shall be able to set the transparency (as checkbox "set transparency for palette entry 0" or - my varoured solution - by popping up the color palette and selecting the color that shall be transparent) when 256colors are selected from the drop down. Thoughts?

Yes, right, i'll try to add it in the 1.90
Pierre.

User avatar
GeorgD
Posts: 258
Joined: Thu Oct 12, 2006 2:45 pm

Postby GeorgD » Mon Dec 04, 2006 4:58 pm

xnview wrote:Yes, right, i'll try to add it in the 1.90

Great :-D

User avatar
adesigninteractive
Posts: 32
Joined: Tue Dec 20, 2005 11:01 am
Location: between Faye and Edward, approximately by now
Contact:

set transparency value to palette entry

Postby adesigninteractive » Tue Apr 10, 2007 9:33 am

i expect this is a redundant topic. if so; if there's a FAQ please FWD me as i couldn't find anything. i found the following to be the "closest match"
viewtopic.php?t=5595

QUESTION:
what is the function of the "option" parameter:

File
.Write
. .GIF
. . .set transparency value to palette entry

thanks.

(i believe i have a similar issue w/ png format, however it appears to be covered, i think, in the other thread i've cited above)
Have a go at these texts featuring graphics and imaging, please.

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

Postby Drahken » Tue Apr 10, 2007 10:21 pm

GIFs, certain PNGs, and a few othe formats have a palette of only 256 colors (vs the 16 million in JPG, certain other PNGs, and most other formats). GIF has single color transparency only (PNG can have either single color transparency or alpha transparency). If you go into the options and set transparency to palette entry 50, then whichever of the 256 colors in your image is located in palette entry 50 will be saved as transparent. This is not a particularly useful option, since i requires you to know exactly which palette slot white (or whatever color you want to be transparent) is in. It's much better to set transparency from the image->edit colormap option. (If the image is currently in truecolor mode, you need to go image->convert to colors to make the edit colormap option work.)

arnaud
Posts: 2
Joined: Wed Jun 20, 2007 1:54 pm

Postby arnaud » Wed Jun 20, 2007 2:02 pm

Hi to all,

On this very same topic, but a little harder question. If I want to batch convert hundreds of pictures which have a consistent background and have them with a transparent background. Is there any possibility to do that ?

I shall first convert them to PNG but then ???

I know that as the background can vary between picture there might be some difficulties. But there should be a way!!!

I have set up some examples here: http://intranet.easyviz.com/gallery2/main.php?g2_itemId=867

arnaud
Posts: 2
Joined: Wed Jun 20, 2007 1:54 pm

Postby arnaud » Wed Jun 20, 2007 2:56 pm

To seek the same result, may be another way to is to replace on the original JPG the background with an uniform color like #ffffff. Is it possible ?

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

Postby XnTriq » Thu Jun 21, 2007 5:35 pm

arnaud wrote:If I want to batch convert hundreds of pictures which have a consistent background and have them with a transparent background.



Return to “XnView - FAQ”

Who is online

Users browsing this forum: No registered users and 1 guest