- Aug 12, 2017
- 707
- 1,952
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
e.g. an image compressed with
will be a bit larger than an image compressed with
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
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)
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
*withno 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
-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 resultse.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
You must be registered to see the links
and all versions (latest included) here
You must be registered to see the links
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.
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).here you can find some images/pictures with transparency to test your settings
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
You must be registered to see the links
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: