### Method

# Vips Image webpsave

#### Declaration [src]

    int
    vips_webpsave (
      VipsImage* in,
      const char* filename,
      ...
    )

#### Description [src]

Write an image to a file in WebP format.

By default, images are saved in lossy format, with `Q` giving the WebP quality factor. It has the range 0 - 100, with the default 75.

Use `preset` to hint the image type to the lossy compressor. The default is `VIPS_FOREIGN_WEBP_PRESET_DEFAULT`.

Set `smart_subsample` to enable high quality chroma subsampling.

Set `smart_deblock` to enable auto-adjusting of the deblocking filter. This can improve image quality, especially on low-contrast edges, but encoding can take significantly longer.

Use `alpha_q` to set the quality for the alpha channel in lossy mode. It has the range 1 - 100, with the default 100.

Use `effort` to control how much CPU time to spend attempting to reduce file size. A higher value means more effort and therefore CPU time should be spent. It has the range 0-6 and a default value of 4.

Use `target_size` to set the desired target size in bytes.

Use `passes` to set the number of entropy-analysis passes, by default 1, unless `target_size` is set, in which case the default is 3. It is not recommended to set `passes` unless you set `target_size`. Doing so will result in longer encoding times for no benefit.

Set `lossless` to use lossless compression, or combine `near_lossless` with `Q` 80, 60, 40 or 20 to apply increasing amounts of preprocessing which improves the near-lossless compression ratio by up to 50%.

Set `exact` to preserve the color data in transparent pixels. This can reduce compression efficiency, but is generally required when working with images as data.

For animated webp output, `min_size` will try to optimize for minimum size.

For animated webp output, `kmax` sets the maximum number of frames between keyframes. Setting 0 means only keyframes. `kmin` sets the minimum number of frames between frames. Setting 0 means no keyframes. By default, keyframes are disabled.

For animated webp output, `mixed` tries to improve the file size by mixing both lossy and lossless encoding.

Use the metadata items `loop` and `delay` to set the number of loops for the animation and the frame delays.

Optional arguments

- `Q`: `gint`, quality factor
- `lossless`: `gboolean`, enables lossless compression
- `exact`: `gboolean`, preserves color values from transparent pixels
- `preset`: `VipsForeignWebpPreset`, choose lossy compression preset
- `smart_subsample`: `gboolean`, enables high quality chroma subsampling
- `smart_deblock`: `gboolean`, enables auto-adjusting of the deblocking filter
- `near_lossless`: `gboolean`, preprocess in lossless mode (controlled by Q)
- `alpha_q`: `gint`, set alpha quality in lossless mode
- `effort`: `gint`, level of CPU effort to reduce file size
- `target_size`: `gint`, desired target size in bytes
- `passes`: `gint`, number of entropy-analysis passes
- `min_size`: `gboolean`, minimise size
- `mixed`: `gboolean`, allow both lossy and lossless encoding
- `kmin`: `gint`, minimum number of frames between keyframes
- `kmax`: `gint`, maximum number of frames between keyframes

See also

`vips_webpload()`, `vips_image_write_to_file()`.

This method is not directly available to language bindings.

#### Parameters

`filename`

  Type: `const char*`

  File to write to.

  The data is owned by the caller of the method.
  The value is a NUL terminated UTF-8 string.

`...`

  Type: ``

  `NULL`-terminated list of optional named arguments.

#### Return value

Type: `int`

0 on success, -1 on error.