0.1.2 • Published 10 months ago

bit-icon v0.1.2

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

bit-icon

Generate 8-bit style icons like the initial GitHub icons. SVG and PNG support.

bit-icon-demo-image

Demo

You can try it here.

Installation

npm install bit-icon

Methods

NameTypeDescriptionExample
toSvg()stringOutput Base64-encoded SVG in DataURIdata:image/svg+xml;base64,PHN2Zz ...
toPng()Promise\<string>Output Base64-encoded PNG in DataURIdata:image/png;base64,iVBORw0KGU ...

Options

NameTypeDefaultDescription
hashstringA hexadecimal string of 22 or more characters used to generate image.If none, it is randomly generated.
sizenumber420The width and height of the image to be generated.
pixelnumber70The size of a single pixel of the icon to be generated.Note that the pixel should be no larger than 1/5 of the size to avoid overflowing.
colorstringThe color of the icon is calculated from the hash value. Use this option to disable that behavior and use the specified color instead. Use Hex,RGB,HSL,HSB. (e.g. #FF0000 or rgb(255,0,0) or hsl(0,100,50) or rgb(0,100,100) for red).
backgroundstring#FFFFFFUsed as the background color of the generated image; use Hex,RGB,HSL,HSB. (e.g. #FF0000 or rgb(255,0,0) or hsl(0,100,50) or rgb(0,100,100) for red).
huenumber[]0,360Used as a range of hue in HSL colors calculated from the hash.
saturationnumber[]45,65Used as a range of saturation in HSL colors calculated from the hash.
lightnessnumber[]55,75Used as a range of lightness in HSL colors calculated from the hash.
type'normal' | 'reverse'| 'random'"normal"It is used to fill in the color of the image to be generated. "normal" has a white background and colored body. "reverse" is the reverse of "normal". "random" is just as the name implies.

Usage

import

import  { BitIcon }  from "bit-icon";

Simple

const bitIcon = new BitIcon();
const svg = bitIcon.toSvg();

// If you use it in HTML
const img = document.createElement('img');
img.src = svg;
document.body.appendChild(img);

Custom

import  { BitIcon, Options }  from "bit-icon";

// Must be at least 22 characters in hexadecimal, such as MD5.
const hash = 'd41d8cd98f00b204e9800998ecf8427e'
const options: Options = {
    size: 100,
    pixel: 15,
    color: "hsl(215,25,27)",
    background: "hsl(214,32,91)",
    hue: [100, 300],
    saturation: [10, 70],
    lightness: [20, 80],
    type: 'reverse'
  };
const bitIcon = new BitIcon(hash, options);
const png = await bitIcon.toPng();

// If you want to download
const link = document.createElement('a');
link.download = 'sample.png';
link.href = png;
link.click();
0.1.2

10 months ago

0.1.1

11 months ago

0.1.0

11 months ago