Closed albertopasqualetto closed 1 year ago
I know the built-in implementation of pngout is not useful, but it's easy enough to bypass using the --use-image-optimizer= flag. Using that flag you can even string together multiple processing steps using your favorite utilities, which will be executed in series (not in parallel) on the same cached image file to progressively optimize it. I use the following (on Windows):
--use-image-optimizer=sam2p,jbig2 --use-image-optimizer="truepng -o4 -g0 -na %(targetfnq)s & ECT -9 --reuse %(targetfnq)s & ECT -9 --allfilters --pal_sort=120 %(targetfnq)s & pngout -f6 -kp -ks %(targetfnq)s & pngout -f6 -kp -n0 %(targetfnq)s & deflopt.exe -b %(targetfnq)s"
Note that "%(targetfnq)s" is some weird symbol standing for the cached image file being optimized.
I call sam2p and jbig2 as two separate optimizers (because I think the default optimizers get turned off if you start specifying them manually) and then the third optimizer is defined using the string of calls enclosed by double-quotes in the second instance of the flag. I think you can have as many flag instances as you want and they will be considered separate optimizers. Just ensure that any CLI programs you call are copied into the pdfsizeopt_XXXexec subfolder alongside the built-in programs.
Why png compression is using
pngout -force *
command?
This is in implementation detail of pdfsizeopt. Using the -force
flag won't actually increase the final image size, because pdfsizeopt records the output image size of each image optimizer (and also the original image size), and picks the smallest.
Why is running pngout -force
flag useful for pdfsizeopt? By using it, pdfsizeopt can distinguish these 3 cases: (1) pngout exists, it has processed the image, and made it smaller; (2) pngout exists, it has processed the image, and made it larger; (3) pngout doesn't exist on the system or it has encountered a runtime error (such as input file not found, output filesystem full, out of memory) processing the image. Without the -force
flag, pdfsizeopt wouldn't be able to distinguish (2) and (3).
Why png compression is using
pngout -force *
command? From what I understood that flag is going to create the output also if the output is larger than the input, which is nosense from a size compression point of view.