vips-rs
Rust bindings for libvips: fast, low-memory image processing with a safe, ergonomic API.
- Safe wrappers over common libvips APIs
- RAII-style initialization/shutdown management
- Practical helpers for reading, transforming, and writing images
Documentation: https://houseme.github.io/vips-rs/vips/
Requirements
- Rust >= 1.80.0
- libvips installed on your system
- macOS:
brew install vips - Linux:
apt-get install -y pkg-config libvips libvips-dev(or your distro equivalent)
- macOS:
Installation
Add to your Cargo.toml:
[]
= "*"
Quick start
use *;
Working with memory
- Own the pixel buffer (simple and recommended):
let pixels = vec!; // RGB
let img = from_memory ?;
let thumb = img.thumbnail ?;
thumb.write_to_file ?;
- Borrow a pixel buffer (make sure the backing data outlives all derived images):
let pixels = vec!;
let img = from_memory_reference ?; // The returned image lifetime is tied to `pixels`
let thumb = img.thumbnail ?;
thumb.write_to_file ?;
Lifetimes and common pitfalls
- Prefer owned constructors (
from_file,from_memory) when possible. - Borrowing constructors (
from_memory_reference) tie the image lifetime to the borrowed slice. Do not let the slice drop before all derived images are fully used. - Keep the creator image in scope while using results that reference it. Avoid creating images inside a short inner scope and returning derived results from it.
API highlights
- Image IO: from file, from raw memory, from borrowed memory, save to file
- Geometry: thumbnail/resize/reduce/shrink
- Drawing: lines, circles, flood fills (in-place)
- Stitching:
merge,mosaic,match_,globalbalance - Interpolation: nearest, bilinear, or custom
The API surface is evolving; see the docs for details and more examples.
Notes
- Initialization: the crate manages
vips_init/vips_shutdownviaVipsInstanceand standard library primitives (OnceLock). - Side effects: most operations return new images; drawing operations modify
self. - If a higher-level wrapper is missing, you can still access lower-level bindings in
vips-sysor usevips::call(...)to invoke libvips operations directly.
License
Changelog
See CHANGELOG.md.