Unable to convert PNG to transparent GIF

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, helmut, xnview

wspollack
Posts: 3
Joined: Wed Apr 07, 2004 2:50 am
Location: Schodack, NY, USA

Unable to convert PNG to transparent GIF

Post by wspollack »

I'm unable to create a transparent GIF from a PNG file (and I have successfully made this exact conversion using this same PNG file, interactively using MWSnap, for instance). The syntax I have tried -- and the background color to be made transparent is white -- have included the following:

nconvert -transpcolor 255 255 255 -o c:\test1.gif c:\test1.png

nconvert -transparent 100 -transpcolor 255 255 255 -o c:\test1.gif c:\test1.png

nconvert -transparent 0 -transpcolor 255 255 255 -o c:\test1.gif c:\test1.png

nconvert -transparent 100 -transpcolor FF FF FF -o c:\test1.gif c:\test1.png

nconvert -transparent 100 -transpcolor FFFFFF -o c:\test1.gif c:\test1.png

None of these has made test1.gif transparent, at least as far as I can tell, although all of them have created the test1.gif file without complaint.

Am I doing something wrong?

Regards,

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

Re: Unable to create transparent GIF from PNG

Post by xnview »

wspollack wrote:I'm unable to create a transparent GIF from a PNG file ...
-transparent is not for that.

you must use :

nconvert -transparent 100 -o c:\test1.gif -out gif c:\test1.png

100 is the index of the transaprent color in the colormap

Pierre.
wspollack
Posts: 3
Joined: Wed Apr 07, 2004 2:50 am
Location: Schodack, NY, USA

I get an error:

Post by wspollack »

If I enter that, here's what happens:

Code: Select all

C:\Program Files\XnView>nconvert -transparent 100 -o c:\test1.gif -out gif c:\te
st1.png
** NCONVERT v4.17 (c) 1991-2004 Pierre-E Gougelet (Feb 17 2004/12:32:24) **
        Version for Windows NT/9x/2000  (All rights reserved)
** This is a freeware software (for non commercial use)

  Error: This picture cannot be written using this format (c:\test1.png)


C:\Program Files\XnView>
test1.png is a valid PNG file, according to all software I've checked.

Any other suggestions?

Thanks for your help,

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

Re: I get an error:

Post by xnview »

wspollack wrote:...
test1.png is a valid PNG file, according to all software I've checked.

Any other suggestions?
Seems that your picture is not colors picture but RGB picture!
Pierre.
wspollack
Posts: 3
Joined: Wed Apr 07, 2004 2:50 am
Location: Schodack, NY, USA

"Properties" of test1.png

Post by wspollack »

Pierre, when I do a Properties on test1.png in Windows Explorer (XP), the Summary tab shows:

Width: 600 pixels
Height: 300 pixels
Horizontal Resolution: 96dpi
Vertical Resolution: 96dpi
Bit Depth: 24
Frame Count: 1

Does this mean it's not a valid PNG file? When I open the file in Ulead Instant Viewer and look at the properites there, the first line says "Data type: RGB True Color (24-bit)." Based on this information, is there some way I can convert this to a GIF, with White as the transparent color?

Thanks,

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

Re: "Properties" of test1.png

Post by xnview »

wspollack wrote:... the first line says "Data type: RGB True Color (24-bit)." Based on this information, is there some way I can convert this to a GIF, with White as the transparent color?
GIF doesn't accept 24bits file, so you must convert it to 256 colours before!
Pierre.
User avatar
helmut
Posts: 8705
Joined: Sun Oct 12, 2003 6:47 pm
Location: Frankfurt, Germany

Re: "Properties" of test1.png

Post by helmut »

xnview wrote:
wspollack wrote:... the first line says "Data type: RGB True Color (24-bit)." Based on this information, is there some way I can convert this to a GIF, with White as the transparent color?
GIF doesn't accept 24bits file, so you must convert it to 256 colours before!
Pierre.
GIF supports only colour maps with up to 256 colours. So you have to reduce the numer of colours of your true colour image (24 bit, 16 Mio. colours) when or before converting to GIF.

Reducing the colours and changing format can be done in one step, this should work:

nconvert -out gif -o output.gif -colors 256 input.png