1.0.0 • Published 5 years ago

sunglass v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

sunglass 😎

Convert image into a given color palette.

Input ImageInput PaletteOutput Image
npm.ionpm.ionpm.io
npm.ionpm.ionpm.io

This project was originally created for my personal website;

API

/**
 * Convert image into a given color palette.
 *
 * @param {Image | HTMLCanvasElement} image      input image
 * @param {string[]}                  [palette=['#fff','#999','#555','#222']]
 *                                        colors of output image
 * @param {string}                    [colorSpace='rgb'] color space
 * @return {HTMLCanvasElement}        output image on canvas
 */
sunglass(image[, palette[, colorSpace]])

Example

import sunglass from 'sunglass';

const img = new Image();
img.onload = () => {
    const palette = ['#d1c4af','#a39990','#363132'];
    const outputCanvas = sunglass(img, palette);
    console.log(outputCanvas.toDataURL()); // base64 string of output image
};
img.src = '...';