pngquant icon indicating copy to clipboard operation
pngquant copied to clipboard

PNGoo - command-line version (cli/cmd)

Open ttodua opened this issue 4 years ago • 9 comments

Hi. I don't know what i am missing, but tried many times with different (transarent) images, and the results I am getting from PNGoo, i cant get with any command line arguments with pngquant. If original file is 300kb, pngquant produces around 150kb, while PNGoo around 50kb.

So, i've switched to use PNGoo from command line. at this moment, i've created Console Application ( dependent project onto PNGoo, which is closed and cant commit there), so, when I drag&drop file, or execute like pngoo-cmd image.png.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using PNGoo;

namespace pngoo_command_line
{
    class Program
    {
        static void Main(string[] args)
        {
            var fileList_ = new List<string>(); 
             
            for (int i = 0; i < args.Length; i++)
            {
                fileList_.Add(args[i]);
            }
            if (fileList_.Count>0)
            {
                string[] fileList = fileList_.ToArray();
                processAll(fileList);
            }
        }

        private static CompressionSettings compressionSettings = new CompressionSettings();

        static void processAll(string[] fileList)
        {
            // let's start the batch
            PNGoo.BatchOperations.BatchFileCompressor batch = new PNGoo.BatchOperations.BatchFileCompressor();
            batch.OutputDirectory = null;
            batch.OutputIfLarger = false;
            batch.CompressionSettings = compressionSettings;
            batch.FilePaths = fileList;
            batch.Start();
        }
    }
}

so, what I ask, can you please add an ability to run PNGoo from command line too? so, the main PNGoo exe could determine if it is run from command-line, it should output form, instead work under cmd.

or otherwise, give us some insights how to run pngquant samely from cmd to get same results as PNGoo.

ttodua avatar Mar 10 '20 21:03 ttodua

All pngoo does is launch pngquant command line. It does nothing else.

kornelski avatar Mar 10 '20 22:03 kornelski

All pngoo does is launch pngquant command line. It does nothing else.

Then how to explain, that when I compressing this file with with PNGoo, i get 5kb output file, but with same settings if i launch pngquant, it produces 20kb output file. Can you advise how to execute pngquant (with what parameters) to get the same result for that file? thanks in advance

ttodua avatar Mar 11 '20 08:03 ttodua

Try setting the same number of colors or quality as the GUI.

Are you calling the same exe as pngoo, or a different version?

It really is just a launcher for pngquant exe:

https://github.com/kornelski/pngoo/blob/f2c614d5cb666ed0eec288138bdd645cfed41e6e/src/PNGoo/Compressor/PNGQuant.cs#L23-L46

kornelski avatar Mar 11 '20 11:03 kornelski


ttodua avatar Mar 11 '20 13:03 ttodua

that's why I am surprised too. and that's why I've linked the example PNG file, and you can see yourself that it will produce unexpected results. I mean, with PNGoo it is produced much less file, while (with same settings) with pngquant it is larger (i've given the exact kilobytes in above post). that's why I needed if you could check what happens (a bug or issue) in any of your app? (either PNGoo or pngquant).


UPDATE: what I observed recently, is that before PNGoo sends to data to pngquant, it has (already by that moment) reduced file size compared to original file size (i've checked the file-size of the "tmp" file that PNGoo creates, and it's really less than original file. and that tmp file data is sent to pngquant as I see)

so, obviously, PNGoo is not just launched of pngquant, instead it does some more file optimization/reduction before sending to pngquant too.

you can try yourself with my above linked .png file and see that is the case.

Would be nice if you integrate that optimization in pngquant too, so we could disregard PNGoo in command-line, and directly use pngquant.

ttodua avatar Mar 11 '20 13:03 ttodua

Did you have a chance (really 1 minute) to confirm that behavior on the above provided sample image? maybe it's related to the bytes of transparency being ignored in PNGoo, and not in PNGquant?

ttodua avatar Mar 18 '20 21:03 ttodua

pngquant is incapable of preserving RGB values of transparent bytes due to the colorspace it uses internally. It couldn't have that bug even if it wanted to :)

Can you provide the tmp file, the direct pngquant, and pnggoo files to compare?

kornelski avatar Mar 19 '20 01:03 kornelski

I have deleted previous messages, and now, briefly, here I am sending a real proof of the misbehavior (which is caused by something I was unable to find, other than that PNGoo does something else).

Here I am attaching several image samples - https://we.tl/t-vsC2aWMItO

in each sample folder, there are 4 images: A) the original png B) with "pngquanti_new" suffix (compressed with pngquant.exe, latest version from website) C) with "pngquanti_old" suffix (compressed with old pngquanti.exe from , latest version from PNGoo's /lib/pngquant/pnqguanti.exe. it does produces same result as that pngoo.exe) D) with "pngoo_new" suffix (compressed with PNGoo.exe, BUT WITH PNGoo/lib/pngquant/pnqguanti.exe replaced actually by latest available pngquant.exe )

so, you see the differences yourself. not only they have different results, but even (B) and (D) have different results (even though the same pngquant exe is used in those occasions)

ttodua avatar Mar 19 '20 11:03 ttodua

well, it's a pitty author ignored this topic. Unfortunately, the above "wetransfer" files has been deleted and I don't have time to generate them again.

just for historical purposes if anyone ever will take a minute to check and confirm themselves, i will attach the original file here - https://drive.google.com/file/d/1yzevMqZz-0fDaJ5nipVw4wrnPeRu36X8/view?usp=sharing

i have already mentioned the steps (only 1 minute needed) to reproduce the problem.

ttodua avatar Jul 13 '20 21:07 ttodua