copy png to png expands palette

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

Moderators: XnTriq, xnview

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

copy png to png expands palette

Post by dlang » Fri Jul 25, 2014 5:21 pm

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: 1843
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: copy png to png expands palette

Post by cday » Fri Jul 25, 2014 5:37 pm

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 » Mon Jul 28, 2014 1:13 pm

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: 1843
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: copy png to png expands palette

Post by cday » Mon Jul 28, 2014 1:47 pm

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: 5317
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: copy png to png expands palette

Post by XnTriq » Wed Jul 30, 2014 3:30 pm

Bug confirmed for 8- as well as 4-bit PNGs :bugconfirmed:
p121155_1.png
Input (old.png)
p121155_1.png (272 Bytes) Viewed 2043 times
p121155_2.png
Output (new.png)
p121155_2.png (329 Bytes) Viewed 2043 times
p121155_3.png
TweakPNG analysis of input (old.png)
p121155_4.png
TweakPNG analysis of output (new.png)

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

Re: copy png to png expands palette

Post by xnview » Thu Aug 07, 2014 9:04 am

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 » Mon Sep 08, 2014 5:03 pm

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: 1843
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: copy png to png expands palette

Post by cday » Tue Sep 09, 2014 2:52 pm

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... :)

Post Reply