• To improve security, we will soon start forcing password resets for any account that uses a weak password on the next login. If you have a weak password or a defunct email, please update it now to prevent future disruption.

Tool Tutorial Webp compression settings (highest quality with max compression)

pk2000

Active Member
Aug 12, 2017
707
1,918
I see more and more developers using webp to reduce the size in images.
And the most common mistake is that they remove the transparency from their pictures.
Bellow I post some examples on how to use cwebp to compress with lossless and lossy compression methods

alpha & transparency preserved
lossless compression (alpha & transparency preserved)<= Best quality
cwebp input.png -mt -lossless -exact -q 100 -m 6 -alpha_q 100 -o webp_lossless_transparrency.webp
lossy compression (maximum compression/highest quality*, alpha & transparency preserved)<=on some files the quality is not so great
cwebp input.png -mt -near_lossless 0 -exact -q 100 -m 6 -alpha_q 100 -o webp_lossy_transparrency.webp
lossy compression (90% compression, alpha & transparency preserved)
cwebp input.png -mt -near_lossless 0 -exact -q 90 -m 6 -alpha_q 100 -o webp_lossy_transparrency.webp
lossy compression (90% compression, 90% quality alpha, transparency preserved)
cwebp input.png -mt -near_lossless 0 -exact -q 90 -m 6 -alpha_q 90 -o webp_lossy_transparrency.webp
lossy compression (100% quality, alpha & transparency preserved)<= Best compression/quality
cwebp input.png -mt -exact -q 100 -m 6 -alpha_q 100 -o webp_lossy_transparrency.webp
lossy compression (90% quality, alpha & transparency preserved)
cwebp input.png -mt -exact -q 90 -m 6 -alpha_q 100 -o webp_lossy_transparrency.webp
lossy compression (90% quality, 90% quality alpha, transparency preserved)
cwebp input.png -mt -exact -q 90 -m 6 -alpha_q 90 -o webp_lossy_transparrency.webp
alpha, no transparency
lossless compression (alpha no transparency)
cwebp input.png -mt -lossless -q 100 -m 6 -alpha_q 100 -o webp_lossless_notransparrency.webp
lossy compression (maximum compression/highest quality*, alpha, no transparency)
cwebp input.png -mt -near_lossless 0 -q 100 -m 6 -alpha_q 100 -o webp_lossy_notransparrency.webp
lossy compression (90% compression, alpha, no transparency)
cwebp input.png -mt -near_lossless 0 -q 90 -m 6 -alpha_q 100 -o webp_lossy_notransparrency.webp
lossy compression (90% compression, 90% quality alpha, no transparency)
cwebp input.png -mt -near_lossless 0 -q 90 -m 6 -alpha_q 90 -o webp_lossy_notransparrency.webp
lossy compression (100% quality, alpha, no transparency)
cwebp input.png -mt -q 100 -m 6 -alpha_q 100 -o webp_lossy_notransparrency.webp
lossy compression (90% quality, alpha, no transparency)
cwebp input.png -mt -q 90 -m 6 -alpha_q 100 -o webp_lossy_notransparrency.webp
lossy compression (90% quality, 90% quality alpha, no transparency)
cwebp input.png -mt -q 90 -m 6 -alpha_q 90 -o webp_lossy_notransparrency.webp
no alpha, no transparency
lossless compression
cwebp input.png -mt -lossless -q 100 -m 6 -o webp_lossless_noalpha.webp
lossy compression (maximum compression/highest quality)
cwebp input.png -mt -near_lossless 0 -q 100 -m 6 -o webp_lossy_noalpha.webp
lossy compression (90% compression)
cwebp input.png -mt -near_lossless 0 -q 90 -m 6 -o webp_lossy_noalpha.webp
lossy compression (100% quality)
cwebp input.png -mt -q 100 -m 6 -o webp_lossy_noalpha.webp
lossy compression (90% quality)
cwebp input.png -mt -q 90 -m 6 -o webp_lossy_noalpha.webp
*with -near_lossless 0 and -q 100 the program will produce images with the highest compression trying to maintain the highest quality. Pay attention that can give mixed results
e.g. an image compressed with
cwebp input.png -near_lossless 0 -exact -q 100 -m 6 -alpha_q 100 -o webp_lossy_transparrency.webp
will be a bit larger than an image compressed with
cwebp input.png -exact -q 100 -m 6 -alpha_q 100 -o webp_lossy_transparrency.webp
but with better quality but not always. Setting to avoid.

(I attached v1.1.0 for windows for convinience)
You can find the latest precompiled binaries here

and all versions (latest included) here


options:
-mt = Use multi-threading for encoding, if possible
-lossless = Encode the image without any loss. For images with fully transparent area, the invisible pixel values (R/G/B or Y/U/V) will be preserved only if the -exact option is used.
-near_lossless int = Specify the level of near-lossless image preprocessing..
This option adjusts pixel values to help compressibility, but has minimal impact on the visual quality. It triggers lossless compression mode automatically. The range is 0 (maximum preprocessing) to 100 (no preprocessing, the default). The typical value is around 60. Note that lossy with -q 100 can at times yield better results.
-exact = Preserve RGB values in transparent area. The default is off, to help compressibility.
-alpha_q int = Specify the compression factor for alpha compression between 0 and 100. Lossless compression of alpha is achieved using a value of 100, while the lower values result in a lossy compression. The default is 100
-q float = Specify the compression factor for RGB channels between 0 and 100. The default is 75.
In case of lossy compression (default), a small factor produces a smaller file with lower quality. Best quality is achieved by using a value of 100.
In case of lossless compression (specified by the -lossless option), a small factor enables faster compression speed, but produces a larger file. Maximum compression is achieved by using a value of 100.
-m int = Specify the compression method to use.
This parameter controls the trade off between encoding speed and the compressed file size and quality. Possible values range from 0 to 6. Default value is 4. When higher values are used, the encoder will spend more time inspecting additional encoding possibilities and decide on the quality gain. Lower value can result in faster processing time at the expense of larger file size and lower compression quality.
here you can find some images/pictures with transparency to test your settings



















edit: attached the zip "convert and rename" for rpgmaker MV/MZ games (or XP, VX, VXACE games if they are shipped with mkxp instead of the original engine).
Extract its contents in the "img" folder and doubleclick either the "lossless (convert and rename).bat" or one of the 3 (quality 100%, 90% or 80%) "lossy (convert and rename).bat" .
It will
- convert the *.png files of the directory "pictures" to *.webp files
- move the *.webp files in the folder "compressed"
- and rename them to *.png. (does not delete the original files)
- convert the *.jpg files of the directory "pictures" to *.webp files
- move the *.webp files in the folder "compressed"
- and rename them to *.jpg. (does not delete the original files)
 
Last edited:

pk2000

Active Member
Aug 12, 2017
707
1,918
Some info about webp hex file signatures (magic number).
The magic number for webp lossy images is
52 49 46 46 ?? ?? ?? ?? 57 45 42 50 56 50 38 20
and for webp lossless images is
52 49 46 46 ?? ?? ?? ?? 57 45 42 50 56 50 38 4C

?? ?? ?? ?? = The size of the file in bytes (uint32) starting at offset 8

example:
We have a webp file that has a size of 1024 bytes
1024 - 8 = 1016
1016 converted in hex is 3F8 or 00 00 03 F8
We reverse the above hex value and we have:
?? ?? ?? ?? = F8 03 00 00

So a lossy webp of 1mb (=1024 bytes) has a signature
52 49 46 46 F8 03 00 00 57 45 42 50 56 50 38 20
and a lossless webp of 1mb
52 49 46 46 F8 03 00 00 57 45 42 50 56 50 38 4C
 
  • Like
Reactions: schwachi

yamipleb

Member
Oct 27, 2018
177
255
there's no point in using -exact and -alpha_q 100
unless the webp documentation is out of date or incorrect, -exact is forcing the encoder to preserve transparent (invisible) color data. that's useless.
similarly, -alpha_q 100 is redundant. that's the default setting.

also the multithreaded implementation of webp encoders is terrible.
better to encode multiple images in parallel instead. it's much faster and more efficient cputime-wise

to simplify things:
encode lossless webp with cwebp -z 9 ,
optionally lower the -z number if you are impatient​
or add -alpha_filter best if you think it's going too fast :LOL:
don't encode lossy webp
please don't. it's horrible​