spritore-core
spritore-core rasterizes SVG icons and builds MapLibre-compatible PNG sprite
sheets with JSON indexes. Use it when a Rust application already owns the SVG
input and wants to handle generated assets in memory.
It supports two common workflows:
- Render one SVG to straight-alpha RGBA pixels for MapLibre's
map.addImage. - Combine multiple rendered icons into a PNG sprite sheet and index.
Most Rust applications can use the spritore crate, which re-exports this API.
Depend on spritore-core directly when you do not need the spritore command.
Install
Or add it to Cargo.toml:
[]
= "0.3.0"
Build a sprite sheet
use ;
The API operates on data supplied by the caller. Read SVG files before calling
render_icon, and write SpriteSheet::png and index_to_json(...) wherever
your application stores sprite assets.
Use BuildOptions { fast: true } for quicker preview generation. The default
mode prioritizes a smaller PNG for final assets.
API overview
render_iconturns one SVG string into aRenderedIcon.render_icon_with_optionsdoes the same withRenderOptions; setsdfto produce a MapLibre SDF icon (alpha-only distance field with 3 logical pixels of padding, radius 8, cutoff 0.25, all scaled by the pixel ratio). Its index entry gets"sdf": true.build_sprite_sheetcombines rendered icons into aSpriteSheet.index_to_jsonconverts the returned index into ready-to-write MapLibre JSON.
Duplicate icon IDs, empty icon collections, invalid SVG, and zero-sized icons
are reported through Error.
SVG limitations
- External resources such as linked images and web fonts are not loaded.
- SVG
<text>is not supported because fonts are not bundled. Text elements may parse successfully but are not rendered.
License
Licensed under either Apache-2.0 or MIT, at your option.