Page 1 of 1

copy png to png expands palette

Posted: Fri Jul 25, 2014 5:21 pm
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.

Re: copy png to png expands palette

Posted: Fri Jul 25, 2014 5:37 pm
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! :) **

Re: copy png to png expands palette

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

Re: copy png to png expands palette

Posted: Mon Jul 28, 2014 1:47 pm
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 ?

Re: copy png to png expands palette

Posted: Wed Jul 30, 2014 3:30 pm
by XnTriq
Bug confirmed for 8- as well as 4-bit PNGs :bugconfirmed:
Input (old.png)
Input (old.png)
p121155_1.png (272 Bytes) Viewed 3160 times
Output (new.png)
Output (new.png)
p121155_2.png (329 Bytes) Viewed 3160 times
TweakPNG analysis of input (old.png)
TweakPNG analysis of input (old.png)
TweakPNG analysis of output (new.png)
TweakPNG analysis of output (new.png)

Re: copy png to png expands palette

Posted: Thu Aug 07, 2014 9:04 am
by xnview
yes i use only 16 or 256 palette colors

Re: copy png to png expands palette

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

Re: copy png to png expands palette

Posted: Tue Sep 09, 2014 2:52 pm
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... :)