using in node with raw image buffer

#49 · closed · 1 comments

View on GitHub ↗

roycw

HI I have an image Buffer. how can i pass it as data to extarctColors

Comments

Namide

Hi @roycw, You can't send a `Buffer` directly to ̀extract-colors`, you need an intermediate library. Below an example with the lib `get-pixels`: Install `extract-colors` and ̀get-pixels`: ```bash npm install extract-colors get-pixels ``` And the Node.js example code: ```javascript const path = require('path') const getPixels = require("get-pixels") const { extractColors } = require('extract-colors') const src = path.join(__dirname, './my-image.jpg') getPixels(src, (err, pixels) => { if(!err) { const data = [...pixels.data] const [width, height] = pixels.shape extractColors({ data, width, height }) .then(console.log) .catch(console.log) } }) ``` --- You can found all the documentation on the [extract-colors website](https://extract-colors.namide.com/guide/). Don't forget to clicks to the Node.js tabs of the code's examples. Does this answer your question?