Method Image.WebP.encode()
- Method encode
string
encode(Image.Image
image
,mapping
(string
:int
|float
|Image.Image
)|void
options
)- Description
Encode an image using the WebP format.
The image to encode has to be at most 16384 pixels in any direction.
Commonly used options:
"alpha"
:Image.Image
If present, the alpha channel for the image will be the green component of this image. Has to be the same size as the
image
"preset"
:int
Initialization for the encoding options. One of PRESET_DEFAULT, PRESET_PICTURE, PRESET_PHOTO PRESET_DRAWING, PRESET_ICON and PRESET_TEXT
"lossless"
:bool
If set, do lossless encoding.
"quality"
:float
Between 0 and 99. If quality is 100+, lossless encoding with quality 70 will be used.
Additionally these advanced options are also supported:
"image_hint"
:int
One of HINT_DEFAULT, HINT_PICTURE, HINT_PHOTO and HINT_GRAPH. Only used in lossless mode
"target_size"
:int
If non zero, sets the desired filesize, in bytes. Takes precedence over quality.
"target_PSNR"
:int
if non-zero, specifies the minimal distortion to try to achieve. Takes precedence over target_size.
"segments"
:int(1..4)
maximum number of segments to use.
"sns_strength"
:int(0..100)
Spatial Noise Shaping. 0=off, 100=maximum.
"filter_strength"
:int(0..100)
0=off
"filter_sharpness"
:int(3bit)
0=off
"filter_type"
:bool
For the type, 0=simple, 1=strong.
autofilter
:bool
If true, automatically adjust the filter strengths
"alpha_compression"
:bool
Select alpha channel encoding format. Currently supported are 0: No alpha and 1: WebP lossless
"alpha_filtering"
:int(0..2)
Select alpha filtering method. 0: none, 1: fast, 2: best. Default if 1.
"alpha_quality"
:int(0..100)
Select the base image quality for the alpha channel.
"pass"
:int(1..10)
The number of entropy analysis passes. Defaults to 1.
"show_compressed"
:bool
"preprocessing"
:bool
If true, do preprocessing (segment-smooth)
"partitions"
:int(2bit)
log2(number of token partitions). Default is set to 0 for easier progressive decoding.
"partition_limit"
:int(0..100)
quality degradation allowed to fit the 512k limit on prediction modes coding (0: no degradation, 100: maximum possible degradation).
"emulate_jpeg_size"
:bool
If true, try to map the quality setting to generate similar sizes when compared to jpeg.
"thread_level"
:int
The maximum number of extra threads to use. Defaults to 0
"low_memory"
:bool
Decrease memory usage at the cost of encoding speed
- Returns
Always returns the encoded image as a string or throws an error.