Skip to content
Convert image into a given color palette
JavaScript
Branch: master
Clone or download
Latest commit a89d773 Jun 15, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
res doc: fix typo Jun 15, 2019
src doc: fix typo Jun 15, 2019
.gitignore chore: 🤖 init Mar 20, 2019
README.md doc: fix typo Jun 15, 2019
karma.conf.js chore: 🤖 init Mar 20, 2019
package-lock.json chore: 🤖 init Mar 20, 2019
package.json doc: add readme Jun 15, 2019
webpack.config.js chore: 🤖 init Mar 20, 2019

README.md

sunglass 😎

Convert image into a given color palette.

Input Image Input Palette Output Image

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 = '...';
You can’t perform that action at this time.