react-color-extractor icon indicating copy to clipboard operation
react-color-extractor copied to clipboard

Cannot load buffer as an image in browser

Open Steffi3rd opened this issue 6 years ago • 2 comments

I'm using image generated on the fly, and it doesn't work. Is there a solution ?

const logo = "http://www.edgebase.com/companies/amazon/logo?width=80&height=80"

<ColorExtractor src={logo} getColors={colors => console.log(colors)} onError={error => console.log(error)} />

Cannot load buffer as an image in browser
    at BrowserImage../node_modules/node-vibrant/lib/image/browser.js.BrowserImage.load (browser.js:64)
    at ColorExtractor._this.useDefaultImageClass (react-color-extractor.es.js:74)
    at react-color-extractor.es.js:67

```

Steffi3rd avatar Feb 15 '19 16:02 Steffi3rd

Hey,

Looking at that error message, it seems like you are passing an image array buffer to the src prop. To render this image and extract colors from it, you might wanna convert this buffer to output base64 image.

The code for this conversion could look something like this -

function(buffer) {
    const bytes = new Uint8Array(buffer);

    const image = document.getElementById('image');
    image.src = 'data:image/png;base64,'+encode(bytes);
};

Let me know if this works 👍

nitin42 avatar Feb 24 '19 11:02 nitin42

Hey,

Looking at that error message, it seems like you are passing an image array buffer to the src prop. To render this image and extract colors from it, you might wanna convert this buffer to output base64 image.

The code for this conversion could look something like this -

function(buffer) {
    const bytes = new Uint8Array(buffer);

    const image = document.getElementById('image');
    image.src = 'data:image/png;base64,'+encode(bytes);
};

Let me know if this works 👍

what is encode? i tried this but its not working

saikiransathpadi avatar Feb 07 '21 08:02 saikiransathpadi