Read, write, and convert formats
The input is input.jpg; the output is output.webp. These examples show the structure of each interface. The reference output was produced by govips and passed format and dimension checks.


All four interfaces have passed format and dimension checks; encoded bytes from different libvips versions are not expected to be identical.
package main
import ( "fmt" "os"
"github.com/davidbyttow/govips/v2/vips")
func main() { if err := vips.Startup(nil); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } defer vips.Shutdown()
image, err := vips.NewImageFromFile("input.jpg") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } defer image.Close()
params := vips.NewWebpExportParams() params.Quality = 82 data, _, err := image.ExportWebp(params) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } if err := os.WriteFile("output.webp", data, 0o644); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) }}import sharp from 'sharp';
try { await sharp('input.jpg') .webp({ quality: 82 }) .toFile('output.webp');} catch (error) { console.error(error); process.exitCode = 1;}import sysimport pyvips
try: image = pyvips.Image.new_from_file("input.jpg", access="sequential") image.write_to_file("output.webp", Q=82)except pyvips.Error as error: print(error, file=sys.stderr) raise SystemExit(1) from error#!/usr/bin/env bashset -euo pipefail
vips copy input.jpg 'output.webp[Q=82]'More than a file-extension change
Section titled “More than a file-extension change”Format conversion decodes and re-encodes pixels. Output quality, metadata, ICC profiles, alpha, animation pages, and codec availability can all change. Quality = 100 or Q=100 does not mean lossless; lossless encoding is a separate option.
The same 1938 × 1292 JPEG at WebP quality 82 produced four 1938 × 1292, 3-band, non-alpha files on 2026-10-12. Byte size differed: govips 399,106, sharp 398,898, and both pyvips and the CLI 402,162. sharp used its bundled libvips 8.18.7; the other three used system libvips 8.17.3. Matching dimensions are not the same encoding.