JPG to PNG with transparent border

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

Moderators: XnTriq, xnview

Post Reply
christianjules
Posts: 3
Joined: Tue Mar 19, 2013 2:40 pm
Location: Gradignan, Aquitaine - France
Contact:

JPG to PNG with transparent border

Post by christianjules » Tue Mar 19, 2013 2:52 pm

Hello,

I would like to convert a JPG to PNG, adding borders at the left and right and making them transparent. I am trying to do that with this command :
nconvert -out png -canvas 300 300 top-center -transpcolor 0 0 0 -merge_alpha 9781895526066.jpg

But I only get two black borders, not transparent. Could someone tell me what is wrong in my commande line, please :shock: ?
The original JPG and the PNG I get are attached.

Btw, I use NCONVERT v6.17 for MacOS X (10.8.2)

Regards,
Christian
Attachments
9781895526066.png
the PNG i get, with black borders
9781895526066.png (77.39 KiB) Viewed 1738 times
9781895526066.jpg
the original JPG
9781895526066.jpg (48.97 KiB) Viewed 1738 times

christianjules
Posts: 3
Joined: Tue Mar 19, 2013 2:40 pm
Location: Gradignan, Aquitaine - France
Contact:

Re: JPG to PNG with transparent border

Post by christianjules » Wed Mar 20, 2013 12:55 pm

Too bad no one seems to have the same need ... :shock:
I have also tried to split it in two separate taks : jpg -> png a first, then adding the transparency with -transpcolor, but I obtain the same result : my black borders are not transparent.
Regards,
Christian

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

Re: JPG to PNG with transparent border

Post by xnview » Wed Mar 20, 2013 3:59 pm

Please try

Code: Select all

nconvert -out png -32bits -bgcolor 255 0 0 -canvas 300 300 top-center
Pierre.

christianjules
Posts: 3
Joined: Tue Mar 19, 2013 2:40 pm
Location: Gradignan, Aquitaine - France
Contact:

Re: JPG to PNG with transparent border

Post by christianjules » Wed Mar 20, 2013 6:30 pm

It works, great !
But what was wrong in my commande line ? I thought the -transpcolor parameter was the appropriate one ...
And also, is the color 255 0 0 pre-defined to be the transparent color pour PNG32 ?
Anyway, thanks a lot for your help.

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

Re: JPG to PNG with transparent border

Post by xnview » Thu Mar 21, 2013 7:57 am

christianjules wrote:It works, great !
But what was wrong in my commande line ? I thought the -transpcolor parameter was the appropriate one ...
And also, is the color 255 0 0 pre-defined to be the transparent color pour PNG32 ?
Anyway, thanks a lot for your help.
-bgcolor has a little problem, if you use -bgcolor 0 0 0 it doesnt work...
Pierre.

User avatar
DOS386
Posts: 291
Joined: Sun Jun 11, 2006 2:43 pm

Re: JPG to PNG with transparent border

Post by DOS386 » Fri Mar 29, 2013 9:48 am

http://newsgroup.xnview.com/viewtopic.php?t=12247

> But what was wrong in my commandline ?

" -32bits" converts 24 bpp to 32 bpp ... but ...

> I thought the -transpcolor parameter was the appropriate one

It should be sufficient ... but does't work for 24 bpp (PNG can, NC can't ... BUG or missing feature) ?

> And also, is the color 255 0 0 pre-defined to be the transparent color pour PNG32 ?

There is no "transparent color pour PNG32" ... transparent RGB color is used only in 24bpp PNG, and it's NOT set to 255 0 0 by PNG spec: http://www.libpng.org/pub/png/spec/1.2/ ... tml#C.tRNS

Note that you have to remove any possible (0,0,0) values (replace them by (0,0,1)) before adding transparency based on a transparent color (0,0,0) ... what's the best way with NC ???

> -bgcolor has a little problem, if you use -bgcolor 0 0 0 it doesnt work...

Works for me (NC 6.17) :shock: But shouldn't "-bgcolor" eat 4 instead of 3 numbers for 32bpp images ?

And "-transpcolor" is either broken or I don't know how to use it.
There is indeed no WinZIP under my rock.

Post Reply