Learn R Programming

rsvg (version 0.2)

rsvg: Render SVG into Bitmap

Description

Render svg image into a high quality bitmap. When both width and height are NULL, the output resolution matches that of the input. When either width or height is specified, the image is scaled proportionally. When both width and height are specified, the image is stretched into the requested size.

Usage

rsvg(svg, width = NULL, height = NULL)

Arguments

svg
path to svg file or raw vector with svg data. Use charToRaw to convert strings into raw vectors.
width
output width in pixels or NULL for default.
height
output height in pixels or NULL for default

Examples

Run this code
# create some svg
tmp <- tempfile()
svglite::svglite(tmp, width = 10, height = 7)
ggplot2::qplot(mpg, wt, data = mtcars, colour = factor(cyl))
dev.off()

# render it into 720p HD
bitmap <- rsvg(tmp, height = 720)
png::writePNG(bitmap, "test.png", dpi = 144)
jpeg::writeJPEG(bitmap, "test.jpg", quality = 1)
webp::write_webp(bitmap, "test.webp", quality = 100)

Run the code above in your browser using DataLab