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


All four bindings 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 { return err } 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 choice.
Sources
Section titled “Sources”- The topic and govips example shape came from the older Chinese notes; resource cleanup and error handling were added here.
- libvips WebP saver options
- sharp output options