rusty-svg
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

rusty-svg

npm package build status

An SVG toolkit based on resvg

This module is compiled to WASM and currently only supports Node.js

Comparing with the backend ReSVG, this module removes text support as it requires complex font loading logic.

Example

Run the following command, it will convert tiger.svg to tiger.png

node tests/index.js
SVG PNG
Tiger.svg Tiger.png

API

new RustySvg(svgStr: string)

Create a new RustySvg instance. This constructor internally runs usvg parser to standarize the input file

rustySvg.cubic_path_to_quad(tolerance: number)

Convert all cubic curves in this file to quadratic curves. Useful for font glyph rendering (which only allows quadratic curves)

rustySvg.to_string(): string

Output the svg to a string

rustySvg.inner_bbox(): BBox

Get a tight bbox which removes all transparent space in every directions of the file

rustySvg.crop(bbox: BBox)

Crop the svg with a given bbox. Combined with .inner_bbox() API, you could remove the transparent space around the file.

NOTE: this API currently do not actually change the content of the SVG. It uses viewbox to hacky display a certain rect of the file only.

rustySvg.render({ width?: number, background?: string })

Render the svg file to a PNG buffer.

  • width config attribute controls the actual width of the PNG file
  • background currently supports reading a solid hex color value as the background of the output PNG file

getter width(): number

Width of the file

getter height(): number

Height of the file

Readme

Keywords

none

Package Sidebar

Install

npm i rusty-svg

Weekly Downloads

1

Version

0.2.0

License

none

Unpacked Size

1.92 MB

Total Files

5

Last publish

Collaborators

  • zimondai