Helper function to create data-uri of a one pixel image with custom color
Copied from unkown author from this SO answer: https://stackoverflow.com/a/33919020/1644131
With npm
:
npm install create-pixel
With yarn
:
yarn add create-pixel
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} />