Method Image.WebP.encode()
- Method
encode
stringencode(Image.Imageimage,mapping(string:int|float|Image.Image)|voidoptions)- 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.ImageIf 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":intInitialization for the encoding options. One of PRESET_DEFAULT, PRESET_PICTURE, PRESET_PHOTO PRESET_DRAWING, PRESET_ICON and PRESET_TEXT
"lossless":boolIf set, do lossless encoding.
"quality":floatBetween 0 and 99. If quality is 100+, lossless encoding with quality 70 will be used.
Additionally these advanced options are also supported:
"image_hint":intOne of HINT_DEFAULT, HINT_PICTURE, HINT_PHOTO and HINT_GRAPH. Only used in lossless mode
"target_size":intIf non zero, sets the desired filesize, in bytes. Takes precedence over quality.
"target_PSNR":intif 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":boolFor the type, 0=simple, 1=strong.
autofilter:boolIf true, automatically adjust the filter strengths
"alpha_compression":boolSelect 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":boolIf 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":boolIf true, try to map the quality setting to generate similar sizes when compared to jpeg.
"thread_level":intThe maximum number of extra threads to use. Defaults to 0
"low_memory":boolDecrease memory usage at the cost of encoding speed
- Returns
Always returns the encoded image as a string or throws an error.