Paletteron is a free to use JavaScript-based tool for scanning images (img elements) and generating color palettes on the front-end. It's plain JavaScript and comes with support for a list of options to make it fi tyou the best.
Before usage, you need to install/include required files.
File hosted by JSDELIVER. Simply add this code to your site:
<script src="https://cdn.jsdelivr.net/gh/williamfridh/Paletteron-Image-Scanner-Palette-Generator@main/dist/Paletteron.min.js"></script>
Download and include Paletteron.min.js or Paletteron.js from the dist folder if you wish to have readable code.
- Include the script in your HTML file.
- Create a new Paletteron object with optional parameters.
- Load an image and call getPalette with the image element.
- The palette will be returned as an array of RGB values.
- Print or do something else cool with the receiver data!
- (Optional step for debugging) Print the palette to an HTML element for debugging by calling printDebuggingPalette.
PARAMETERS:
- scale - The scale to downscale the image with (recommended is 0.3).
- colorsToPick - The amount of colors to pick from the image (recommended is 5).
- minCoverage - The minimum coverage of a color to be included in the palette (recommended is 0).
- minWhiteDistance - Percentage of maximum color space distance to be min to include color (recommended is 0).
- minBlackDistance - Percentage of maximum color space distance to be min to include color (recommended is 0).
PARAMETERS:
- palette - The resulting palette returned from getPalette().
- paletteElement - The element to which it should print the debugging palette.
Before sending the img element to Palettereon, you need to make sure it's fully loaded. This can be done in many different ways. For instance:
const img = imgHolder.querySelector('img');
const paletteElement = imgHolder.querySelector('.palette');
if (img.complete) {
console.log('Image already loaded');
const palette = paletteron.getPalette(img);
paletteron.printDebuggingPalette(palette, paletteElement);
} else {
img.addEventListener('load', () => {
console.log('Image loaded');
const palette = paletteron.getPalette(img);
paletteron.printDebuggingPalette(palette, paletteElement);
});
}
If you find a bug or have a feature request, please create an issue on GitHub.