I want to get image’s BlurHash so first I’m taking the raw Binary and passing it to sharp() function to get metaData and then pass it to blurHash function but it keep giving me this error
Width and height must match the pixels array
Here is my code
async function imgEncoder() {
try {
const res = await axios("https://s4.anilist.co/file/anilistcdn/media/anime/banner/132473-Lxge5Xq2A6HC.jpg", { responseType: 'arraybuffer' });
const imageBuffer = res.data;
// Log the image buffer to check if it's retrieved correctly
console.log("Image Buffer:", imageBuffer);
// Get metadata using sharp
const metaData = await sharp(imageBuffer).raw().metadata();
console.log("Metadata:", metaData);
const { width, height } = metaData;
const blurhash = encode(width, height, new Uint8ClampedArray(imageBuffer));
console.log("Blurhash:", blurhash);
} catch (err) {
console.log("Error: " + err.message);
}
}
imgEncoder();
Thanks in Advance 🙂
Please Help