Skip to main content

load_svg

Function load_svg 

Source
pub fn load_svg(data: &[u8]) -> Option<DynamicImage>
Expand description

Rasterize an SVG’s bytes to a DynamicImage, or None if it won’t parse.

The image crate has no SVG support, so this is the vector path: usvg parses the document, resvg paints it onto a tiny-skia pixmap, and we hand the pixels back as an RgbaImage the rest of the pipeline treats like any decoded raster. We render at a fixed target resolution (scaling the SVG’s own size so its longer side is ~[SVG_TARGET_PX]) rather than its intrinsic size: an SVG may declare a tiny viewport, and rasterizing that small would leave the consumer upscaling a blurry thumbnail. System fonts are loaded so an SVG that draws real <text> (not outlined paths) still renders its glyphs.