Convert backgrounds in images to transparent PNG files using flood fill from edges, with optional color filling and edge smoothing. Use this skill when the user needs to make images background transparent.
This skill provides a utility to convert backgrounds in images to PNG files with transparency. Uses flood fill from edges to detect and remove backgrounds while preserving the actual shape of the content. Optionally fill non-transparent pixels with a solid color and apply edge smoothing for anti-aliased results.
uv run python .claude/skills/transparent_bg/transparent_bg.py <image_path> [options]
Note: For brevity, examples below use transparent_bg.py - prepend the full path .claude/skills/transparent_bg/ when running.
The script will:
_transparent.png suffix-bg, --bg-color - Background color to remove (default: "#FFFFFF")
-t, --threshold - Color distance threshold for background matching (0-255, default: 30)-f, --fill-color - Fill non-transparent pixels with a color
-s, --smooth-edges - Edge smoothing kernel size (0 = no smoothing, 2-5 recommended, default: 0)-e, --erode - Shrink non-transparent area by N iterations (0 = none, 1-3 recommended, default: 0)# Basic usage - remove white background with default settings
transparent_bg.py image.jpg
# Remove white background with tighter tolerance (safer for light-colored content)
transparent_bg.py dragon.png --threshold 5 --erode 4 --smooth-edges 2
# Remove blue background
transparent_bg.py image.jpg --bg-color "#0000FF" --threshold 10
# Remove green screen with higher tolerance
transparent_bg.py video_frame.png --bg-color "#00FF00" --threshold 50
# Remove background and fill foreground with white
transparent_bg.py icon.png --fill-color white --smooth-edges 2
# Remove background, fill with black, and smooth edges
transparent_bg.py logo.png --fill-color black --threshold 10 --smooth-edges 3
# Custom RGB fill color
transparent_bg.py image.png --fill-color "255,0,0" --erode 2
# Remove edge fringe with erosion
transparent_bg.py photo.jpg --threshold 10 --erode 3 --smooth-edges 2
# Semi-transparent fill (alpha channel supported in fill-color)
transparent_bg.py image.png --fill-color "#00000080" --smooth-edges 2
# Create watermark effect with 50% opacity
transparent_bg.py logo.png --fill-color "255,255,255,128" --threshold 5
floodfill() from all four corners to detect and remove backgrounds. This preserves the actual shape of content better than simple threshold-based matching.--bg-color and --fill-color support:
--fill-color, ALL non-transparent pixels will be filled with the specified color. Supports alpha channel for semi-transparent fills (e.g., watermarks).The script will automatically install Pillow if it's not available.