background-removal-js icon indicating copy to clipboard operation
background-removal-js copied to clipboard

Error: Unsupported format:

Open milosworks opened this issue 10 months ago • 1 comments

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 Image

milosworks avatar May 02 '25 18:05 milosworks

Include the mimetype manually with the image;

const blob = new Blob([imageBuffer], { type: "image/jpeg" });
const removed = await removeBackground(blob)

eth0izzle avatar Jun 18 '25 19:06 eth0izzle