Please bookmark this page to avoid losing your image tool!

Image Baggage Remover Tool

(Free & Supports Bulk Upload)

Drag & drop your images here or

The result will appear here...
You can edit the below JavaScript code to customize the image tool.
function processImage(originalImg, removalMode = "background", tolerance = "30") {
    // "Baggage" could refer to background clutter or EXIF metadata.
    // Drawing to a canvas natively strips EXIF metadata. 
    // If removalMode is "background", we additionally apply a flood-fill algorithm 
    // to remove the surrounding color based on the four corners.
    
    const tol = parseInt(tolerance, 10) || 30;
    const canvas = document.createElement('canvas');
    const width = originalImg.naturalWidth || originalImg.width;
    const height = originalImg.naturalHeight || originalImg.height;
    
    canvas.width = width;
    canvas.height = height;
    const ctx = canvas.getContext('2d', { willReadFrequently: true });
    
    // Draw the image, inherently stripping metadata (EXIF "baggage")
    ctx.drawImage(originalImg, 0, 0);
    
    if (removalMode.toLowerCase() === "metadata") {
        return canvas;
    }
    
    // Extract Image Data for Background/Edge Clutter Removal
    const imgData = ctx.getImageData(0, 0, width, height);
    const data = imgData.data;
    
    function getPixel(x, y) {
        if (x < 0 || y < 0 || x >= width || y >= height) return null;
        const idx = (y * width + x) * 4;
        return [data[idx], data[idx + 1], data[idx + 2], data[idx + 3]];
    }
    
    function matchColor(idx, target) {
        const r = data[idx];
        const g = data[idx + 1];
        const b = data[idx + 2];
        const a = data[idx + 3];
        
        if (a === 0) return false; // Already transparent
        
        const diff = Math.max(
            Math.abs(r - target[0]),
            Math.abs(g - target[1]),
            Math.abs(b - target[2])
        );
        return diff <= tol;
    }
    
    function floodFill(startX, startY) {
        const startColor = getPixel(startX, startY);
        // Stop if invalid or already fully transparent
        if (!startColor || startColor[3] === 0) return;
        
        const stack = [[startX, startY]];
        
        while (stack.length > 0) {
            const [x, y] = stack.pop();
            let currentY = y;
            let idx = (currentY * width + x) * 4;
            
            // Traverse up
            while (currentY >= 0 && matchColor(idx, startColor)) {
                currentY--;
                idx -= width * 4;
            }
            
            currentY++;
            idx += width * 4;
            
            let reachLeft = false;
            let reachRight = false;
            
            // Traverse down
            while (currentY < height && matchColor(idx, startColor)) {
                // Erase pixel (set to transparent)
                data[idx] = 0;
                data[idx + 1] = 0;
                data[idx + 2] = 0;
                data[idx + 3] = 0;
                
                if (x > 0) {
                    const leftIdx = idx - 4;
                    if (matchColor(leftIdx, startColor)) {
                        if (!reachLeft) {
                            stack.push([x - 1, currentY]);
                            reachLeft = true;
                        }
                    } else {
                        reachLeft = false;
                    }
                }
                
                if (x < width - 1) {
                    const rightIdx = idx + 4;
                    if (matchColor(rightIdx, startColor)) {
                        if (!reachRight) {
                            stack.push([x + 1, currentY]);
                            reachRight = true;
                        }
                    } else {
                        reachRight = false;
                    }
                }
                
                currentY++;
                idx += width * 4;
            }
        }
    }
    
    // Initiate flood fill from all four corners to clear outer boundary baggage 
    floodFill(0, 0);
    floodFill(width - 1, 0);
    floodFill(0, height - 1);
    floodFill(width - 1, height - 1);
    
    ctx.putImageData(imgData, 0, 0);
    return canvas;
}

Free Image Tool Creator

Can't find the image tool you're looking for?
Create one based on your own needs now!

Description

The Image Baggage Remover Tool is designed to clean up image files by removing unwanted elements such as background clutter or embedded EXIF metadata. Users can choose to strip metadata to protect privacy or use the background removal mode, which employs a flood-fill algorithm to eliminate surrounding colors from the edges of the image. This tool is useful for privacy preservation, preparing images for graphic design projects, or creating transparent assets by removing distracting backgrounds.

Leave a Reply

Your email address will not be published. Required fields are marked *