1.3.1 • Published 1 year ago

bgsvg v1.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Random SVG background generator

Generate beautiful random SVG backgrounds on Node.js runtime.

CI NPM Version NPM Downloads

Installation

npm i -S bgsvg
# or
yarn add bgsvg

Supported SVG backgrounds

Meteors

import { meteors } from "bgsvg";

const svg = await meteors({
  width: 800,
  height: 300,
  background: {
    colors: ["#000000", "#13137f"],
  },
  color: "#ba8003",
  densityX: 30,
  densityY: 2,
  thickness: 4,
  bidirectional: true,
  output: {
    type: "svg",
  },
});

console.log(svg);
// <svg xmlns="http://www.w3.org/2000/svg" width="800" height="300" viewBox="0 0 800 300"...
OptionDefault valueDescription
width-Width of the SVG
height-Height of the SVG
background-Background of the SVG
color-Color of the meteors
densityX30Average density of meteors on X-Axis
densityY2Average density of meteors on Y-Axis
thickness4Thickness of meteors
bidirectionaltrueShow meteors falling and rising
output{type: 'svg'}Output format

SVGs can have a solid color or a gradient background depending on the value of the background option.

export type CanvasBackground =
  | string
  | {
      x1?: string;
      y1?: string;
      x2?: string;
      y2?: string;
      colors: [string, string];
    };

You can generate SVG, PNG, JPEG, and Webp image based on the output option. When the output format is not SVG, then an image Buffer is returned.

type OutputTypeSvg = { type: "svg" };
type OutputTypePng = { type: "png" };
type OutputTypeWebp = { type: "webp" };
type OutputTypeJpeg = { type: "jpeg"; quality?: number };

rain

import { rain } from "bgsvg";

const svg = await rain({
  width: 800,
  height: 300,
  background: {
    colors: ["#27274c", "#121242"],
  },
  color: "#8f97c1",
  densityX: 20,
  densityY: 15,
  thickness: 1,
  randomness: 4,
});

console.log(svg);
// <svg xmlns="http://www.w3.org/2000/svg" width="800" height="300" viewBox="0 0 800 300"...
OptionDefault valueDescription
width-Width of the SVG
height-Height of the SVG
background-Background of the SVG
color-Color of the rain drops
densityX20Average density of drops on X-Axis
densityY15Average density of drops on Y-Axis
thickness1Thickness of the drop
randomness4Randomness of the drops (more value, the less)
output{type: 'svg'}Output format

Development

Installation

yarn install

Preview server

yarn preview

This commands starts an express server at http://localhost:3003 to display how the SVGs would look like.

Test

yarn test
1.3.1

1 year ago

1.3.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago