copy png to png expands palette

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

Moderators: XnTriq, helmut, xnview

dlang
Posts: 2
Joined: Fri Jul 25, 2014 5:18 pm

copy png to png expands palette

Post by dlang »

If you copy an 8bit png which uses only a few colors, say 10 and copy using "ncvonert -o new.png old.png", your new image has a palette of 256 colors expanding the size of the image (bytes on disk, not image dimension). The size of the image is critical since I am placing them in an Android apk package and want the smallest possible png.
cday
XnThusiast
Posts: 3945
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: copy png to png expands palette

Post by cday »

dlang wrote:If you copy an 8bit png which uses only a few colors, say 10 and copy using "ncvonert -o new.png old.png", your new image has a palette of 256 colors ...
Please try adding the following code from the NConvert Help file:

-colors num : Convert in Indexed Colors (256, 216, 128, 64, 32, 16 or 8 )

So

Code: Select all

nconvert -colors 16 -o new.png old.png
** Please post NConvert questions under the NConvert heading -- Everyone! :) **
dlang
Posts: 2
Joined: Fri Jul 25, 2014 5:18 pm

Re: copy png to png expands palette

Post by dlang »

Using -colors <numColors> is not practical when I am converting a bunch of images using a DOS "for" loop command.

for %f in (*.png) do nconvert -o out\%f %f

I also do not know the number of color used in each image.
I only determined that nconvert was expanding the palette because some of my images got larger (size on disk).
I used tweakPng to display the file details and noticed the palette size increased.

I am using nconvert to strip off some of the meta chunk sections (text, iText, and zText).
cday
XnThusiast
Posts: 3945
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: copy png to png expands palette

Post by cday »

dlang wrote:Using -colors <numColors> is not practical when I am converting a bunch of images using a DOS "for" loop command.

Code: Select all

for %f in (*.png)  do nconvert -o out\%f  %f
Is not practical because... ? It doesn't run, or some other reason?
I also do not know the number of color used in each image.
If you open an image in a GUI image editor such as XnView you should be able to see the image properties including the number of colours, or you could upload an example image.[/quote]
I used tweakPng to display the file details and noticed the palette size increased.
But that shows the number of colours??

When a png file is opened NConvert may convert it to a 24-bit image while preserving the actual colours used; when you use the -colours option you would need to set a value equal to greater than the number of colours in the original image.
I am using nconvert to strip off some of the meta chunk sections (text, iText, and zText).
You should be able to do that using the following flag:

-rmeta : Remove Metadata (EXIF/IPTC/...)

Have you created a list of the available NConvert commands using -help ?
User avatar
XnTriq
Moderator & Librarian
Posts: 6320
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: copy png to png expands palette

Post by XnTriq »

Bug confirmed for 8- as well as 4-bit PNGs :bugconfirmed:
p121155_1.png
p121155_2.png
p121155_3.png
p121155_4.png
You do not have the required permissions to view the files attached to this post.
User avatar
xnview
Author of XnView
Posts: 43132
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: copy png to png expands palette

Post by xnview »

yes i use only 16 or 256 palette colors
Pierre.
User avatar
DOS386
Posts: 291
Joined: Sun Jun 11, 2006 2:43 pm

Re: copy png to png expands palette

Post by DOS386 »

XnTriq wrote:Bug confirmed for 8- as well as 4-bit PNGs
I would NOT consider this as a BUG ... NC is neither a hard-core PNG optimizer nor a generic file copy tool, so to me it seems to work well, despite somewhat unfortunate result is this special case. Try OPTIPNG or PNGOUT or TRUEPNG or similar. http://newsgroup.xnview.com/viewtopic.php?t=23326

> and want the smallest possible png

PS: some other PNG creation tools save pictures always as 32-bpp RGBA, even if there are just 5 colours in ... so NC is NOT that bad :-\
There is indeed no WinZIP under my rock.
cday
XnThusiast
Posts: 3945
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: copy png to png expands palette

Post by cday »

DOS386 wrote:[I would NOT consider this as a BUG ... NC is neither a hard-core PNG optimizer nor a generic file copy tool, so to me it seems to work well, despite somewhat unfortunate result is this special case.
A ´bug´becomes a ´limitation´when it is documented as such... :)