0.1.0 • Published 5 years ago

create-pixel v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

create-pixel

Helper function to reate data-uri of a one pixel image with custom color

Credits

Copied from unkown author from this SO answer: https://stackoverflow.com/a/33919020/1644131

Setup

With npm:

npm install create-pixel

With yarn:

yarn add create-pixel

Usage

import createPixel from 'create-pixel'

// Other option with a number: createPixel(0xff0000)
const dataUri = createPixel('#ff0000')

// Use in a generated image src:
const onePixelImage = new Image()
onePixelImage.src = dataUri
document.body.appendChild(onePixelImage)

// Or in a JSX component:
<img src={dataUri} />