TruePNG is actually one of the most advanced PNG optimizer available. it does an exhaustive checks for reductions and should be able to transform image with more efficiency than other tools. those transformations are called
an image reduction is a data transformation that reduces PNG file size losslessly for Web. most of PNG optimizers do reductions, but the more the tool will do, the more it will be able to optimize PNG files. that is the reason why TruePNG can beat some tools, even if they are using strong compression algorithm.
TruePNG does trials to find the best colortype for a PNG file. at the beginning of this process, it should transform the RGB area that let it to choose the optimal colortype with more precision.
|34,8 KB||9,66 KB|
unlike PNGOUT, TruePNG does some transformations and then chooses the best colortype for this image: paletted mode. that is not a lossy process for a Web usage, because both images will be the same. PNGOUT uses a stronger compression algorithm, but TruePNG gets a best result thanks to this « transformation ».
TruePNG does some other trials that are not done automatically (or not done at all) by other tools:
- TruePNG can test grayscale if image is graylevel
- it tests tRNS chunk instead of alpha channel if applicable
- it reduces truecolor+alpha to grayscale+alpha
- it can choose truecolor, even if image contains less than 256 colors (or less)
- TruePNG can encode to palette mode even if image is graylevel
|22,7 KB||6,17 KB|
The bitdepth should match to the colortype, with some exceptions in paletted mode. encoders have the choice to use 8, 4, 2 or 1 bit by pixel. most of the time, the best choice is to select the lower bitdepth, that should decrease the filesize. this feature is included in most of optimizers.
|Number of colors||Bitdepth|
|17 to 256 colors||8 bits / pixel|
|5 to 16 colors||4 bits / pixel|
|3 or 4 colors||2 bits / pixel|
|1 or 2 colors||1 bit / pixel|
most of encoders, including TruePNG, choose the minimal bitdepth possible considering the number of colors in the image. sometimes, it is better to choose the 8 bits / pixels, even for an image that have 16 colors or less. TruePNG can check that, and it reduces filesize that way.
|4 bits||8 bits|
|6,82 KB||6,39 KB|
TruePNG is also different from other tool (including OptiPNG) because of its palette optimizer. like most of them, it detects an entry that does not correspond to RGB data — unused, or same entries values that have different coordinates in RGB. that way, it truncates the palette at the number of colors that are used.
|21 KB||17 KB|
the real good point is the order of entries in palette. it tries to optimize the sorting, sometimes againts logical way, prefering a heavy tRNS chunk — 256 transparent entries where 10 are really useful, but a smaller iDAT, mainly because of the filtering that is used.
TruePNG palette optimization trials
TruePNG does some trials to sort the colors to get the smallest file. It tries to sort the colors by popularity, by colors or by luminance. all those trials are done in memory with fast settings (huffman only for compression, filter 0 and 5) and it picks the smallest output.
|Popularity ascending||Popularity descending|
the first method that TruePNG can use is the ordering by popularity, also used by another programs. it counts the number of time that a color is used in the picture, then move it to the top of palette, and does the same with the next one. this is an effective way to store most of paletted PNG.
|Luminance ascending||Luminance descending|
sorting is done according the following calculation 0,299R + 0,587G + 0,114B. colors which have most brightness are moved to the top of the palette. this method is also used by another programs, like PNGOptimizer or OptiPNG. this could be very effective on images which have a lot of gradients.
|Colors ascending||Colors descending|
the palette can be sorted using another combination using the following transformation, consisting to collect the first bit of each RGB bytes of an entry in palette, and does the same with following bits to the end. this can be good for pictures that contains gradients.
RGB: 255,230,241 255 ==
101100 110 110
according to the version of TruePNG, it also uses another trials with differents methods, that can be done in RGB, YUV or L*a*b* colorspace, with a different reference color at start.
|Method||Color space||Color reference|
|Nearest||RGB, YUV, L*a*b*||most popular, most bright or most dark color|
|Nearest (W)||RGB, YUV, L*a*b*||most popular, most bright or most dark color|
|Nearest (N)||RGB, YUV, L*a*b*||most popular, most bright or most dark color|
- Nearest: each subsequent color in the palette is taken as the most similar to the previous one. it is done with Euclidean distance:
sqr(R1-R2) + sqr(G1-G2) + sqr(B1-B2) [+sqr(A1-A2)]
- Nearest (W): « W » means weight, and is the closest color value multiplied by the popularity of color which is indirectly correlated with the context of the image.
- Nearest (N): « N » means neighbor, and is the value of the color multiplied by a factor of popularity in the immediate environment.
Palette and transparency
TruePNG is considering the alpha values in a palette to sort colors. it is usually better to store all transparents colors at the top of the palette, because of unnecessary tRNS values affected for non-transparent colors.
|21,1 KB||17,4 KB|
but in some cases, it is better to have colors sorted, even if it makes a big tRNS chunk, because the sorting could reduce the iDAT with more efficiency. TruePNG adds combinations for sorting transparency values and selects the smaller output.
- ignore: that ignores the transparent value, considering only the colors;
- sort: sort transparency values, considering the colors
- start: sort all transparency values at the top of the palette, considering the colors.
If you use the
-a1 switch for paletted PNG, TruePNG will try to add a new test, by changing the RGB value of a fully transparent color to 255,255,255. this should add a new trial that change the ordering, and it will select the smaller output.
|Original||TruePNG -a0||TruePNG -a1|
|22,4 KB||19,4 KB||18,9 KB|
this tRNS optimization can also be done for grayscale or true color images. TruePNG can turn from 0,0,0 to 255,255,255 the transparent color specified in the tRNS chunk:
|TruePNG -a0||TruePNG -a1|
|11,6 KB||11,5 KB|
RGB values that are not displayed
this feature is enabled by default. it detects the occurrency between a pixel and the alpha value: if alpha value is 0, then it converts the RGB data to 0 for all channels. this pixel will not be displayed anyway and it makes it more compressible that way.
|44,7 KB||41,4 KB|
when the alpha value is 0, the pixel is not displayed whatever the RGB values. if you use
-a1, TruePNG should transform an image by modifying those RGB values to make it more compressible. instead of just turning the value to 0,0,0, it does the following transformations, and pick up the smallest result.
|RGB to 0,0,0||RGB to 255,255,255||RGB data to Up|
|RGB data to Right||RGB data to Down||RGB data to Left|
each image is tested with -zc6 -zm8 -zs0,1 -f0,1,2,5 as internal settings trials, that could explain why TruePNG could be slow on large images. the
-a1 option will also try to optimize the file keeping the RGB data as they are. if it is better without modifications, TruePNG should use it for the image:
|Original||-a0 (modified)||-a1 (not modified)|
|36,3 KB||11,0 KB||9,22 KB|
TruePNG can use heuristic filtering with the -f5 switch. it uses methods that are differents from the one defined in PNG specification. the most complete job is done by -fe that tries filter combinations without using one or more specific filter for the line. that's seems not optimal, but it could be better for overall image compression.
if you care about time, the generic profile
-f0,5) should be faster, because it tries only without filtering, and with an adaptative heuristic filter. it should be nice enought for most kind of images.
the lossy optimization is most the time the best way to optimize an image for web. TruePNG can do lossy by quantization, that consists to reduce the number of colors, with or without conversion to palette mode. in a more recent approch, it can do a lossy averaging filter that denoises the image to make it more compressible.
Lossy averaging filter
TruePNG significantly reduces PNG size by doing a lossy averaging filter, that consists to modify data for a specific filter. this method works well with the average filter, so perhaps you could try to use with it. it gives nice speed - size ratio, specially for truecolor images.
|90,6 KB||58,5 KB|
truepng-f3 -l image.png
it is good for images that can not be converted to palette mode because of quality loss. at this time, this feature is still experimental and a better implementation is on the way: combination of image transformation and lossy filter can be used to get an even smaller result.
the color quantization consists to reduce the number of colors in an image. you should consider to use the lossy averaging filter instead specially with big images, because color quantization can be very slow on some samples. Also, it should give a lower quality - size ratio.
|original (31896 colors)||Color Quantizer (1024 colors)|
|90,6 KB||36,2 KB|
truepng-f0 -cq c=1024 image.png
-cq switch active the quantization, and user have to specify a value for
c= which represents the approximative amount of colors there will be in the image. if you use a value below 257, the PNG could be converted to paletted mode.
Conversion to palette mode
TruePNG can use color quantization to convert an image to paletted mode that will significantly reduce the filesize. at this time, TruePNG includes an old implementation of color quantization, it is preferable to use Color Quantizer instead.
|17,3 KB||8,95 KB|
you can use
c= to specify the number of colors, and
d= switch if you want to active the dithering. note that dithering is optionnal, and can help to keep a better visual perception if there are lot of colors in the image.
interlacing is a method of encoding that displays the image partially according to received data. PNG uses the Adam7 algorithm to display with interlacing. if you care about file size, you should always disable interlacing: most of the time, it makes files bigger.
|With interlacing||Without interlace|
|11,5 KB||8,95 KB|
-i0 switch should disable the interlacing. it makes file bigger, specially with those that are using a filter to store the data. if you need smaller files to display them faster, you sould consider optimization, quantization or lossy averaging filter instead of using interlacing.
in most of cases, it is better to disable any chunk that correct the way the image is displayed, specially for Web. gAMA chunk is not an exception, and the
-g0 should delete it. However, TruePNG let you to merge the way the image is displayed instead of using gAMA chunk.
|With gAMA chunk||Gamma integrated|
|9,08 KB||7,08 KB|
truepng-g1 image.png -out test.png
be warned, it is a no back process, so you should make a backup of your file (or use -out switch). gAMA chunk can be added or deleted, but in this case, it changes RGB values in the new file.
for a web usage, PNG chunks are more often a problem instead of a solution, because some of them can modify the way the image is displayed: some devices can use them, some can not. TruePNG deletes all unnecessary chunks with the
-md remove all instruction:
truepng-md remove all image.png
|/f#||PNG delta filters 0=None, 1=Sub, 2=Up, 3=Average, 4=Paeth, 5=Mixed
|/fe||PNG delta filters combination to get the smallest output size. That overrides /f#|
|/i#||0 deletes the interlacing, 1 should active or keep existing interlacing|
|/na||Disable the RGB data optimization for fully transparent pixels|
|/nc||Disable most of optimization, including color type or bitdepth changes|
|/np||TruePNG will not change palette ordering|
|/nz||TruePNG will not compress the file. It works with /md switch for chunks deletion.|
|/tz||TruePNG compresses tEXt chunk|
|/md||This switch can delete some chunks:
|/cq||Enable color quantization to reduce the number of colors:
|/l||Enable the lossy filtering (use with -f):
|/zc||Zlib compression level, from 1 to 9|
|/zm||Zlib memory level, from 1 to 9|
|/zs||Zlib compression strategy from 0 to 3|
|/zw||Zlib window size from 0 to 7 (0-7 corresponds to 256, 512, 1024, 2048, 4096, 8192, 16384 and 32768)|
|/quiet||Quiet mode, will not display informations|
|/force||Always write the file, even if it's bigger|
|/out||Specify where you want to write the file:
|/y||Overwrites the file if it exists|
|/t||Preserves the time and date|
|/info||Displays PNG file informations|
TruePNG also works if you drag and drop files on the
TruePNG.exe file. it will use the /o1 profile to optimize in this case. if you plan to combine it with other tools, TruePNG should be the at the beginning of process because of those reductions. an example of a combination, if you want to optimize your image for Web:
:: TruePNG optimization
truepng-o1 -g0 -i0 -md remove all image.png
:: libdeflate compression
advdef-z -2 image.png