0.4.2 • Published 6 months ago

svg-artisan v0.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

npm version

SVG-Artisan

Simple SVG builder/generator for NodeJS.

Inspired by svg-builder by Joseph Chapman.

Installation

pnpm

pnpm i svg-artisan

npm

npm i svg-artisan

Example

import { RawElement, node, Style, Svg } from 'svg-artisan';

// SVG Root element
const svg = new Svg().width(300).height(300);

// Add child element
const text = node.text({ 'font-weight': 'bold', x: 10, y: 10 }, 'Lorem ipsum');
svg.appendChild(text);

// Add multiple elements
const element1 = node.rect(/* ... */);
const element2 = node.line(/* ... */);
const element3 = node.text(/* ... */);
svg.appendChild(element1, element2, element3);

// Add other/custom element (advanced)
const gradient = RawElement.create(
    'gradient', // Element or tag name
    { id: 'myGradient' }, // Attributes
    [
        /* Content or child element(s) inside this `gradient` element */
    ]
);
const defs = RawElement.create('defs').appendChild(gradient);
svg.appendChild(defs);

// Add style
const style = Style.create({}, '#myText { font-weight: bold; }');
svg.appendChild(style);

// Render SVG
const data = svg.render();

// Render as Buffer
const svgBuffer = svg.buffer();

Validate SVG

Currently, this library does not validate the elements and attributes.

If you want to validate the generated SVG, use is-svg npm package.

Rasterize SVG

To convert SVG into raster format (PNG, JPG, etc) programmatically, you can use npm package such as sharp, gm, or other image processor.

References

0.4.2

6 months ago

0.4.1

6 months ago

0.4.0

6 months ago

0.3.0

6 months ago

0.2.2

6 months ago

0.2.1

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago