background-removal-js
background-removal-js copied to clipboard
Error: Unsupported format:
This is my current code
import { readFile, writeFile } from 'node:fs/promises'
import { removeBackground } from '@imgly/background-removal-node'
import { fileTypeFromBuffer } from 'file-type'
try {
const img = await readFile('./valve.png')
const res = await fileTypeFromBuffer(img)
console.log(res)
const removed = await removeBackground(img, {
debug: true,
output: { format: 'image/png', quality: 1 }
})
await writeFile('./removed-valve.jpg', await removed.bytes())
} catch (error) {
console.error(error)
}
Its clear that this image is png, my logs clearly state so
{ ext: 'png', mime: 'image/png' }
Idk why specifically this library does not detect it as png
Include the mimetype manually with the image;
const blob = new Blob([imageBuffer], { type: "image/jpeg" });
const removed = await removeBackground(blob)