resvg is a high-performance SVG rendering library written in Rust. It can function as a Rust library, a C library, and a CLI application, making it versatile for various use cases involving static SVG files.
SVG is complex, with the SVG 1.1 specification running nearly 900 pages. resvg aims to support the entire SVG spec. Its vast test suite, featuring around 1600 tests, ensures correctness. This suite is open to the public, aiding developers who wish to create their own SVG libraries.
Written entirely in Rust, resvg boasts minimal use of unsafe
code, enhancing memory safety. It rigorously checks for issues like endless loops and stack overflows, crucial when processing random inputs such as SVG/XML, CSS, TTF, PNG, JPEG, GIF, and GZIP.
The resvg CLI application is less than 3MB and has no external dependencies. It includes only what's necessary for rendering SVG files, ensuring a lean and efficient tool.
resvg works on all platforms where Rust can be compiled, including WASM. Although there are minor challenges with obscure CPU architectures and mobile OSs, overall, it offers broad compatibility.
resvg separates SVG parsing and rendering into two distinct steps, facilitated by two libraries: resvg and usvg. This allows developers to create custom renderers using any 2D library.
With resvg leveraging [tiny-skia] for rendering, it delivers impressive performance. There is ongoing potential for further optimization.
resvg's independence from system libraries ensures consistent results across all supported platforms. An SVG rendered on one platform will produce identical images on another, down to each pixel.
resvg focuses on the static SVG subset, excluding elements like a
, script
, view
, or cursor
, and excluding events and animations. Progress on SVG 2 support can be tracked through the svg2 tag and the SVG 2 changelog. Support for SVG Tiny 1.2 is neither available nor planned.
The resvg project encompasses more than just the resvg library. It includes several auxiliary libraries developed to enable resvg's functionality:
Despite its relatively small size (around 2500 lines of code for the library), the entire resvg project comprises nearly 75,000 lines of code, reflecting its comprehensive capabilities.
rs_pbrt is a Rust crate implementing the PBRT book's C++ code for physically based rendering.