0.7.0 • Published 7 years ago
@ismay/silkscreen v0.7.0
silkscreen
pointillize a raster image to svg
Silkscreen allows you to render a raster image to svg. It does so by converting the pixels to svg shapes, with a configurable size. This gives the result a pointillized, or silkscreened appearance.
Installation
$ npm install @ismay/silkscreen
Example
So to silkscreen an image to dots of 25 by 25 pixels, with a 1 pixel gap:
const lena = require('lena');
const silkscreen = require('@ismay/silkscreen');
const svg = silkscreen(lena, {
sample: [25, 25],
padding: [1, 1]
});
fs.writeFileSync('./lena.svg', svg);
Which would yield this result:
API
silkscreen(image, options) ⇒ string
Converts an ndarray of an image to an svg
Kind: global function Returns: string - The svg as a string
Param | Type | Default | Description |
---|---|---|---|
image | ndarray | Ndarray of the image to convert to an svg. Use get-pixels to convert an image to an ndarray. | |
options | Object | {} | Configuration options |
options.sample | Array | 5,5 | The width and height in pixels per sample, must be positive |
options.padding | Array | 0,0 | Padding applied to each shape in px |
options.shape | string | "ellipse" | The svg shape to generate, either rect or ellipse |
options.pattern | string | A predefined shape sizing pattern, either linear , diagonal , radial or alpha | |
options.attributes | Object | {} | An object with attributes to add to each shape |