diff --git a/content/collections/tools/object-eraser.json b/content/collections/tools/object-eraser.json
index 040745c..0221c58 100644
--- a/content/collections/tools/object-eraser.json
+++ b/content/collections/tools/object-eraser.json
@@ -17,14 +17,13 @@
"pageType": "masking",
"showThumbnailsSection": false,
"thumbnailPlacement": "after-upload",
- "twoImagesConfig": {
- "firstImageLabel": {
- "en": "1. Primary Subject Photo",
- "hi": "1. मुख्य विषय फोटो"
- },
- "secondImageLabel": {
- "en": "2. Reference / Target Photo",
- "hi": "2. संदर्भ / लक्ष्य फोटो"
+ "maskingConfig": {
+ "maskParamName": "mask",
+ "imageParamName": "image",
+ "defaultBrushSize": 32,
+ "allowCustomMaskUpload": true,
+ "autoMask": {
+ "enabled": false
}
},
"tryIt": {
diff --git a/management/pages/tools/object-eraser/tool.config.json b/management/pages/tools/object-eraser/tool.config.json
index c63e0fd..0221c58 100644
--- a/management/pages/tools/object-eraser/tool.config.json
+++ b/management/pages/tools/object-eraser/tool.config.json
@@ -14,17 +14,16 @@
"homeApp": "bg-cleaner-app",
"alsoIn": [],
"featured": false,
- "pageType": "two-images",
+ "pageType": "masking",
"showThumbnailsSection": false,
"thumbnailPlacement": "after-upload",
- "twoImagesConfig": {
- "firstImageLabel": {
- "en": "1. Primary Subject Photo",
- "hi": "1. मुख्य विषय फोटो"
- },
- "secondImageLabel": {
- "en": "2. Reference / Target Photo",
- "hi": "2. संदर्भ / लक्ष्य फोटो"
+ "maskingConfig": {
+ "maskParamName": "mask",
+ "imageParamName": "image",
+ "defaultBrushSize": 32,
+ "allowCustomMaskUpload": true,
+ "autoMask": {
+ "enabled": false
}
},
"tryIt": {
diff --git a/src/components/tools/DynamicToolWorkspace.tsx b/src/components/tools/DynamicToolWorkspace.tsx
index e28b4f2..2c0ccf7 100644
--- a/src/components/tools/DynamicToolWorkspace.tsx
+++ b/src/components/tools/DynamicToolWorkspace.tsx
@@ -14,7 +14,10 @@ import {
RefreshCw,
FolderOpen,
Zap,
- Crop
+ Crop,
+ Camera,
+ CheckCircle2,
+ Trash2
} from 'lucide-react';
import {
ToolItem,
@@ -165,9 +168,11 @@ export function DynamicToolWorkspace({
setResultUrl(null);
setErrorMessage('');
setStatus('idle');
- setViewMode('studio'); // Transition straight into the editing workspace!
- if (typeof window !== 'undefined') {
- window.scrollTo({ top: 0, behavior: 'smooth' });
+ if (pageType !== 'two-images') {
+ setViewMode('studio'); // Transition straight into the editing workspace!
+ if (typeof window !== 'undefined') {
+ window.scrollTo({ top: 0, behavior: 'smooth' });
+ }
}
};
@@ -177,8 +182,14 @@ export function DynamicToolWorkspace({
setErrorMessage('Please upload a valid JPG, PNG, or WebP photo.');
return;
}
+ const maxBytes = (tool.tryIt?.limits?.maxMB || 12) * 1024 * 1024;
+ if (file.size > maxBytes) {
+ setErrorMessage(`File exceeds max size of ${tool.tryIt?.limits?.maxMB || 12}MB.`);
+ return;
+ }
setSecondaryFile(file);
setSecondaryPreview(URL.createObjectURL(file));
+ setErrorMessage('');
};
const handleLoadSample = (sampleUrl: string) => {
@@ -272,14 +283,18 @@ export function DynamicToolWorkspace({
// 3. Mask Image (for masking archetype)
if (pageType === 'masking') {
const maskParamName = tool.maskingConfig?.maskParamName || 'mask';
+ let maskBlob: Blob | null = null;
if (getMaskBlobRef.current) {
- const maskBlob = await getMaskBlobRef.current();
- if (maskBlob) {
- formData.append(maskParamName, maskBlob, 'mask.png');
- if (maskParamName !== 'mask') {
- formData.append('mask', maskBlob, 'mask.png');
- }
- }
+ maskBlob = await getMaskBlobRef.current();
+ }
+ if (!maskBlob || !hasMaskDrawn) {
+ setStatus('error');
+ setErrorMessage('Please paint over the object or upload a custom mask to erase.');
+ return;
+ }
+ formData.append(maskParamName, maskBlob, 'mask.png');
+ if (maskParamName !== 'mask') {
+ formData.append('mask', maskBlob, 'mask.png');
}
}
@@ -526,12 +541,24 @@ export function DynamicToolWorkspace({
{pageType === 'masking' && primaryPreview && (
-
- Inpainting & Object Masking Studio
-
-
- Paint over areas to remove or replace
-
+
+
+ Inpainting & Object Masking Studio
+
+
+ — Paint over areas with brush or upload custom mask
+
+
+
+ fileInputRef.current?.click()}
+ className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-body font-semibold text-accent bg-accent/10 hover:bg-accent/20 transition-colors cursor-pointer"
+ >
+
+ Change Photo
+
+
{/* Primary Image Slot */}
-
- {resolveLocalised(tool.twoImagesConfig?.firstImageLabel, locale) || 'Primary Photo'}
-
-
+
+
+ {resolveLocalised(tool.twoImagesConfig?.firstImageLabel, locale) || '1. Primary Photo'}
+
+ {primaryPreview && (
+ fileInputRef.current?.click()}
+ className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-xl text-[11px] font-sans font-semibold text-accent bg-accent/10 hover:bg-accent/20 transition-colors cursor-pointer"
+ >
+
+ Change Photo
+
+ )}
+
+
{
+ if (e.target.files?.[0]) handlePrimaryFileSelect(e.target.files[0]);
+ }}
+ />
+
{primaryPreview ? (
- // eslint-disable-next-line @next/next/no-img-element
-
+ <>
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+
+
fileInputRef.current?.click()}
+ className="absolute top-3 right-3 px-3 py-1.5 rounded-full bg-slate-900/80 hover:bg-slate-900 text-white text-xs font-medium backdrop-blur-md shadow-md flex items-center gap-1.5 transition-all opacity-90 hover:opacity-100 cursor-pointer"
+ >
+
+ Change Photo 1
+
+ >
) : (
-
+
fileInputRef.current?.click()}
+ className="w-full h-full flex flex-col items-center justify-center p-4 text-muted text-xs cursor-pointer hover:bg-paper transition-colors"
+ >
Upload primary photo
@@ -642,27 +703,52 @@ export function DynamicToolWorkspace({
{/* Secondary Image Slot */}
-
- {resolveLocalised(tool.twoImagesConfig?.secondImageLabel, locale) || 'Reference / Style Photo'}
-
-
+
+
+ {resolveLocalised(tool.twoImagesConfig?.secondImageLabel, locale) || '2. Reference / Style Photo'}
+
+ {secondaryPreview && (
+ secondaryFileInputRef.current?.click()}
+ className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-xl text-[11px] font-sans font-semibold text-accent bg-accent/10 hover:bg-accent/20 transition-colors cursor-pointer"
+ >
+
+ Change Photo
+
+ )}
+
+
{
+ if (e.target.files?.[0]) handleSecondaryFileSelect(e.target.files[0]);
+ }}
+ />
+
{secondaryPreview ? (
- // eslint-disable-next-line @next/next/no-img-element
-
+ <>
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+
+
secondaryFileInputRef.current?.click()}
+ className="absolute top-3 right-3 px-3 py-1.5 rounded-full bg-slate-900/80 hover:bg-slate-900 text-white text-xs font-medium backdrop-blur-md shadow-md flex items-center gap-1.5 transition-all opacity-90 hover:opacity-100 cursor-pointer"
+ >
+
+ Change Photo 2
+
+ >
) : (
-
+ secondaryFileInputRef.current?.click()}
+ className="w-full h-full flex flex-col items-center justify-center p-4 text-muted text-xs cursor-pointer hover:bg-paper transition-colors"
+ >
Click to upload reference photo
- {
- if (e.target.files?.[0]) handleSecondaryFileSelect(e.target.files[0]);
- }}
- />
-
+
)}
@@ -909,47 +995,117 @@ export function DynamicToolWorkspace({
{pageType === 'two-images' && (
- {/* Image 1 Dropzone */}
-
fileInputRef.current?.click()}
- className="p-5 rounded-2xl border-2 border-dashed border-rule hover:border-accent bg-paper hover:bg-accent/5 transition-all cursor-pointer flex flex-col items-center justify-center text-center space-y-2 min-h-[160px]"
- >
- {
- if (e.target.files?.[0]) handlePrimaryFileSelect(e.target.files[0]);
- }}
- />
-
-
- {resolveLocalised(tool.twoImagesConfig?.firstImageLabel, locale) || '1. Source Face'}
-
- Click to choose
-
+ {/* Image 1 Slot */}
+
{
+ if (e.target.files?.[0]) handlePrimaryFileSelect(e.target.files[0]);
+ }}
+ />
+ {primaryPreview ? (
+
+
+
+
+ {resolveLocalised(tool.twoImagesConfig?.firstImageLabel, locale) || '1. Primary Photo'}
+
+ {
+ e.stopPropagation();
+ setPrimaryFile(null);
+ setPrimaryPreview(null);
+ }}
+ className="text-slate-400 hover:text-red-500 p-1 transition-colors cursor-pointer"
+ title="Remove photo"
+ >
+
+
+
+
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+
+
+
fileInputRef.current?.click()}
+ className="w-full py-2 px-3 rounded-xl bg-slate-100 hover:bg-slate-200 text-slate-800 text-xs font-semibold flex items-center justify-center gap-1.5 transition-colors cursor-pointer"
+ >
+
+ Change Photo 1
+
+
+ ) : (
+
fileInputRef.current?.click()}
+ className="p-5 rounded-2xl border-2 border-dashed border-rule hover:border-accent bg-paper hover:bg-accent/5 transition-all cursor-pointer flex flex-col items-center justify-center text-center space-y-2 min-h-[180px]"
+ >
+
+
+ {resolveLocalised(tool.twoImagesConfig?.firstImageLabel, locale) || '1. Primary Photo'}
+
+ Click to choose image
+
+ )}
- {/* Image 2 Dropzone */}
-
secondaryFileInputRef.current?.click()}
- className="p-5 rounded-2xl border-2 border-dashed border-rule hover:border-accent bg-paper hover:bg-accent/5 transition-all cursor-pointer flex flex-col items-center justify-center text-center space-y-2 min-h-[160px]"
- >
- {
- if (e.target.files?.[0]) handleSecondaryFileSelect(e.target.files[0]);
- }}
- />
-
-
- {resolveLocalised(tool.twoImagesConfig?.secondImageLabel, locale) || '2. Target Body/Photo'}
-
- Click to choose
-
+ {/* Image 2 Slot */}
+
{
+ if (e.target.files?.[0]) handleSecondaryFileSelect(e.target.files[0]);
+ }}
+ />
+ {secondaryPreview ? (
+
+
+
+
+ {resolveLocalised(tool.twoImagesConfig?.secondImageLabel, locale) || '2. Reference Photo'}
+
+ {
+ e.stopPropagation();
+ setSecondaryFile(null);
+ setSecondaryPreview(null);
+ }}
+ className="text-slate-400 hover:text-red-500 p-1 transition-colors cursor-pointer"
+ title="Remove photo"
+ >
+
+
+
+
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+
+
+
secondaryFileInputRef.current?.click()}
+ className="w-full py-2 px-3 rounded-xl bg-slate-100 hover:bg-slate-200 text-slate-800 text-xs font-semibold flex items-center justify-center gap-1.5 transition-colors cursor-pointer"
+ >
+
+ Change Photo 2
+
+
+ ) : (
+
secondaryFileInputRef.current?.click()}
+ className="p-5 rounded-2xl border-2 border-dashed border-rule hover:border-accent bg-paper hover:bg-accent/5 transition-all cursor-pointer flex flex-col items-center justify-center text-center space-y-2 min-h-[180px]"
+ >
+
+
+ {resolveLocalised(tool.twoImagesConfig?.secondImageLabel, locale) || '2. Reference Photo'}
+
+ Click to choose image
+
+ )}
- Open Fusion Studio
+
+ {primaryPreview && secondaryPreview
+ ? 'Open Fusion Studio (Both Photos Ready)'
+ : primaryPreview || secondaryPreview
+ ? 'Continue to Studio'
+ : 'Open Fusion Studio'}
+
)}
diff --git a/src/components/tools/MaskCanvasEditor.tsx b/src/components/tools/MaskCanvasEditor.tsx
index 44866cc..39e032e 100644
--- a/src/components/tools/MaskCanvasEditor.tsx
+++ b/src/components/tools/MaskCanvasEditor.tsx
@@ -11,7 +11,8 @@ import {
Eye,
EyeOff,
RotateCcw,
- Maximize2
+ Maximize2,
+ UploadCloud
} from 'lucide-react';
import { MaskingConfig, resolveLocalised } from '@/types';
import { ProcessingOverlay } from './ProcessingOverlay';
@@ -38,6 +39,7 @@ export function MaskCanvasEditor({
const containerRef = useRef
(null);
const imageRef = useRef(null);
const maskCanvasRef = useRef(null);
+ const maskFileInputRef = useRef(null);
const [tool, setTool] = useState<'brush' | 'eraser'>('brush');
const [brushSize, setBrushSize] = useState(config?.defaultBrushSize || 32);
@@ -169,6 +171,85 @@ export function MaskCanvasEditor({
saveHistory();
};
+ // Upload and parse custom mask file (supports B&W or transparent PNG)
+ const handleCustomMaskUpload = (e: React.ChangeEvent) => {
+ const file = e.target.files?.[0];
+ if (!file) return;
+
+ const reader = new FileReader();
+ reader.onload = () => {
+ const img = new Image();
+ img.onload = () => {
+ const canvas = maskCanvasRef.current;
+ if (!canvas) return;
+
+ const ctx = canvas.getContext('2d', { willReadFrequently: true });
+ if (!ctx) return;
+
+ // Sample and scale uploaded mask to match base canvas dimensions
+ const tempCanvas = document.createElement('canvas');
+ tempCanvas.width = canvas.width;
+ tempCanvas.height = canvas.height;
+ const tempCtx = tempCanvas.getContext('2d', { willReadFrequently: true });
+ if (!tempCtx) return;
+
+ tempCtx.drawImage(img, 0, 0, canvas.width, canvas.height);
+ const uploadedData = tempCtx.getImageData(0, 0, canvas.width, canvas.height);
+ const uD = uploadedData.data;
+
+ // Check if uploaded mask has alpha transparency
+ let hasAlphaVariation = false;
+ for (let i = 0; i < uD.length; i += 16) {
+ if (uD[i + 3] < 240) {
+ hasAlphaVariation = true;
+ break;
+ }
+ }
+
+ // Apply interactive red overlay on canvas
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+ const maskOverlay = ctx.createImageData(canvas.width, canvas.height);
+ const mD = maskOverlay.data;
+
+ for (let i = 0; i < uD.length; i += 4) {
+ const r = uD[i];
+ const g = uD[i + 1];
+ const b = uD[i + 2];
+ const a = uD[i + 3];
+
+ let isMasked = false;
+ if (hasAlphaVariation) {
+ // Non-transparent pixels count as mask
+ isMasked = a > 40;
+ } else {
+ // Solid B&W mask: bright/white pixels (> 50 brightness) count as mask
+ const brightness = 0.299 * r + 0.587 * g + 0.114 * b;
+ isMasked = brightness > 50;
+ }
+
+ if (isMasked) {
+ mD[i] = 239; // R
+ mD[i + 1] = 68; // G
+ mD[i + 2] = 68; // B
+ mD[i + 3] = 160; // Alpha
+ } else {
+ mD[i + 3] = 0;
+ }
+ }
+
+ ctx.putImageData(maskOverlay, 0, 0);
+ saveHistory();
+ setHasDrawnMask(true);
+ onMaskChange?.(true);
+
+ // Reset input value so re-selecting same file triggers onChange
+ e.target.value = '';
+ };
+ img.src = reader.result as string;
+ };
+ reader.readAsDataURL(file);
+ };
+
// Convert canvas pointer coordinate to natural canvas pixels
const getCanvasCoords = (e: React.PointerEvent) => {
const canvas = maskCanvasRef.current;
@@ -213,7 +294,9 @@ export function MaskCanvasEditor({
const handlePointerDown = (e: React.PointerEvent) => {
if (e.button !== 0 && e.pointerType === 'mouse') return;
- e.currentTarget.setPointerCapture(e.pointerId);
+ try {
+ e.currentTarget.setPointerCapture(e.pointerId);
+ } catch {}
setIsDrawing(true);
const { x, y } = getCanvasCoords(e);
@@ -396,6 +479,24 @@ export function MaskCanvasEditor({
Eraser (Sub)
+ {/* Upload Custom Mask Button */}
+
+ maskFileInputRef.current?.click()}
+ className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-body font-semibold text-accent bg-accent/10 border border-accent/20 hover:bg-accent/20 transition-colors cursor-pointer"
+ title="Upload an external black-and-white or transparent PNG mask"
+ >
+
+ Upload Custom Mask
+
+
{/* Auto-Mask Detection Button (if configured) */}
{config?.autoMask?.enabled !== false && (
setIsHovered(true)}
- onMouseLeave={() => {
- setIsHovered(false);
- setCursorPos(null);
- }}
- className="relative w-full max-h-[600px] overflow-hidden rounded-2xl bg-paper-2 border border-rule flex items-center justify-center cursor-crosshair select-none isolate"
+ className="relative w-full max-h-[600px] overflow-hidden rounded-2xl bg-paper-2 border border-rule flex items-center justify-center select-none isolate p-2 sm:p-4"
>
- {/* Underlying Image */}
- {/* eslint-disable-next-line @next/next/no-img-element */}
-
-
- {/* Mask Overlay Canvas */}
- setIsHovered(true)}
+ onMouseLeave={() => {
+ setIsHovered(false);
+ setCursorPos(null);
}}
- className="absolute inset-0 w-full h-full object-contain pointer-events-auto transition-opacity"
- />
-
- {/* Live Circular Brush Size Cursor Indicator */}
- {isHovered && cursorPos && (
-
+ {/* Underlying Image */}
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+
- )}
+
+ {/* Mask Overlay Canvas */}
+
+
+ {/* Live Circular Brush Size Cursor Indicator */}
+ {isHovered && cursorPos && (
+
+ )}
+
{/* Laser Scanning Processing Animation Overlay */}
{isProcessing && }
{/* Canvas Helper Hint */}
-
-
💡 Paint over objects, tourists, or areas you wish to modify or erase.
-
- {hasDrawnMask ? 'Mask ready for processing' : 'No mask drawn yet'}
+
+ 💡 Paint over objects with the brush, or upload an external custom mask image (B&W or PNG).
+
+ {hasDrawnMask ? '✓ Mask ready for inpainting' : 'No mask drawn yet'}
diff --git a/src/types/index.ts b/src/types/index.ts
index d277adf..09627d1 100644
--- a/src/types/index.ts
+++ b/src/types/index.ts
@@ -195,6 +195,7 @@ export interface MaskingConfig {
maskParamName?: string;
imageParamName?: string;
defaultBrushSize?: number;
+ allowCustomMaskUpload?: boolean;
}
export interface TwoImagesConfig {