Skip to content

Instantly share code, notes, and snippets.

@klucar
Created July 8, 2015 15:59
Show Gist options
  • Save klucar/690b047c5b4c8be03924 to your computer and use it in GitHub Desktop.
Save klucar/690b047c5b4c8be03924 to your computer and use it in GitHub Desktop.
NodeJS script to extract the color palette of a PNG
// usage: node png_colors.js | sort | uniq
//
// ignores alpha
var PNG = require('png-js');
var myimage = PNG.load('my_image.png');
myimage.decodePixels(function (pixels) {
for( var ii = 0; ii < pixels.length; ii = ii + 4){
console.log( pixels.readUInt32BE(ii).toString(16).substring(0,6));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment