Add Remove Background feature using AI (rembg)

Frontend:
- Added "Remove Background (AI)" to Image menu
- Created remove_background.js module with dialog options
- Added removeBackground method to API service

Backend:
- Added /tools/remove-background-base64 endpoint for miniPaint frontend
- Uses rembg library for AI-powered background removal

Features:
- Automatically detects main subject and removes background
- Option to create as new layer or replace current
- Enables transparency mode after removal
- Works with any image layer
This commit is contained in:
Claude
2026-01-27 00:47:22 +00:00
parent f650ec3019
commit 22d9f767a8
4 changed files with 221 additions and 0 deletions
+24
View File
@@ -71,6 +71,30 @@ class ApiService {
return response.json();
}
/**
* Remove background from image using AI (rembg)
* @param {string} imageData - Base64 encoded image data
* @returns {Promise<{result: string, width: number, height: number}>} - Base64 encoded result with transparency
*/
async removeBackground(imageData) {
const response = await fetch(`${this.baseUrl}/tools/remove-background-base64`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
image: imageData,
}),
});
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Unknown error' }));
throw new Error(error.detail || `Remove background request failed: ${response.status}`);
}
return response.json();
}
/**
* Health check for the backend
* @returns {Promise<boolean>}