### Method

# Vips Image pngsave

#### Declaration [src]

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

#### Description [src]

Write a VIPS image to a file as PNG.

`compression` means compress with this much effort (0 - 9). Default 6.

Set `interlace` to `TRUE` to interlace the image with ADAM7 interlacing. Beware than an interlaced PNG can be up to 7 times slower to write than a non-interlaced image.

Use `filter` to specify one or more filters, defaults to none, see `VipsForeignPngFilter`.

The image is automatically converted to RGB, RGBA, Monochrome or Mono + alpha before saving. Images with more than one byte per band element are saved as 16-bit PNG, others are saved as 8-bit PNG.

Set `palette` to `TRUE` to enable palette mode for RGB or RGBA images. A palette will be computed with enough space for `bitdepth` (1, 2, 4 or 8) bits. Use `Q` to set the optimisation effort, `dither` to set the degree of Floyd-Steinberg dithering and `effort` to control the CPU effort (1 is the fastest, 10 is the slowest, 7 is the default). This feature requires libvips to be compiled with libimagequant.

The default `bitdepth` is either 8 or 16 depending on the interpretation. You can also set `bitdepth` for mono and mono + alpha images, and the image will be quantized.

XMP metadata is written to the XMP chunk. PNG comments are written to separate text chunks.

Optional arguments

- `compression`: `gint`, compression level
- `interlace`: `gboolean`, interlace image
- `filter`: `VipsForeignPngFilter`, row filter flag(s)
- `palette`: `gboolean`, enable quantisation to 8bpp palette
- `Q`: `gint`, quality for 8bpp quantisation
- `dither`: `gdouble`, amount of dithering for 8bpp quantization
- `bitdepth`: `gint`, set write bit depth to 1, 2, 4, 8 or 16
- `effort`: `gint`, quantisation CPU effort

See also

`vips_image_new_from_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.