Fix AI Cutout White Halos and Opaque SVG White Boxes
Visual symptom: Jagged 1–2px white fringe around transparent product PNGs on dark cards | SVG icon renders inside solid #FFFFFF square or vanishes in dark mode Transparent product PNGs display ugly jagged white fringes against dark UI cards, OR exported AI brand SVGs render inside an opaque white square box and vanish completely when users switch to dark mode.
Raster cutouts generated on white backdrops and passed through crude background-removal plugins retain white anti-aliased edge pixels; AI vector generators routinely inject a full-canvas white <rect> backdrop layer and hardcode #000000/#111111 strokes instead of CSS currentColor.
Copy-Paste Verified Fix
# 1. Inspect raw SVGs for stray full-canvas white <rect> backdrops and hardcoded black strokes
grep -rnE '<rect[^>]*fill="#(fff|ffffff|F7F7F5)"' ./raw-svgs || echo "No white backdrop rects found"
# 2. Optimize via SVGO cleanly (preserving viewBox!)
npx svgo -f ./raw-svgs -o ./public/images/icons --multipass --precision=2
# 3. For monochrome UI icons, strip full-bleed white <rect> and replace #111111 / #000000 with currentColor
# (Run on monochrome icon sets only — keep brand accent fills bound to CSS tokens!)
node --input-type=module -e '
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
for (const f of readdirSync("./public/images/icons").filter(x => x.endsWith(".svg"))) {
const p = join("./public/images/icons", f);
let s = readFileSync(p, "utf8");
s = s.replace(/<rect[^>]*width="(?:100%|1024|512)"[^>]*fill="#(?:fff|ffffff|FFF|FFFFFF)"[^>]*\/>/g, "");
s = s.replace(/(stroke|fill)="#(?:000|000000|111|111111)"/gi, "$1=\"currentColor\"");
writeFileSync(p, s);
}
' Before vs. After (Broken Pattern vs. Verified Fix)
<svg width="1024" height="1024"><rect width="1024" height="1024" fill="#FFFFFF"/><path stroke="#000000" d="M12.123456..."/></svg> <svg viewBox="0 0 1024 1024" fill="none"><path stroke="currentColor" stroke-width="24" d="M12.12..."/></svg> Why this works: Removing the white <rect>, preserving integer viewBox, rounding decimals to 2 places via SVGO, and binding monochrome strokes to currentColor makes every icon crisp across Daylight and Darkroom themes.
Why This Failure Happens in Real Pipelines
When an image generator draws a glass bottle, ceramic mug, or sneaker on a white studio background, edge pixels are mathematically blended 50% product + 50% pure white (#FFFFFF). Post-hoc background removers cut away pure white cleanly but leave those semi-blended edge pixels intact—creating an unmistakable jagged white halo the moment you place the PNG over a charcoal #141413 dark card. Generating natively in RGBA transparency (background: "transparent" via OpenAI GPT-Image-2.6) solves this at the source by synthesizing genuine alpha edges and soft translucent shadows.
Vector AI tools such as Recraft suffer a different SVG hygiene bug: they frequently emit a bottom-layer <rect width="1024" height="1024" fill="#ffffff"/> background plus hardcoded #000000 strokes and 6-decimal coordinate bloat. Stripping the root white <rect>, running svgo --multipass --precision=2 (explicitly preserving viewBox!), and swapping monochrome strokes to currentColor drops icon size by 60–80% while making dark-mode theme flips automatic.
Step-by-Step Resolution & Verification
- 01
Generate raster product cutouts natively in RGBA transparency
Call OpenAI GPT-Image-2.6 with background: "transparent" and PNG or WebP output (billed by tokens at $30 per 1M image output tokens; OpenAI publishes no per-image price) instead of stripping white studio backgrounds afterward—especially for glass, shadows, and apparel edges.
- 02
Strip full-canvas white <rect> backdrops and run SVGO (--precision=2)
Remove any bottom white rectangle node from Recraft or Figma SVG exports and verify an explicit integer viewBox="0 0 W H" stays intact.
- 03
Bind monochrome icon strokes to currentColor and convert RGBA PNGs to WebP
Swapping hardcoded #000000 strokes to currentColor fixes dark-mode visibility automatically, while sharp WebP (alphaQuality: 95) cuts transparent PNG weight 55–70%.
grep -rnE 'fill="#(fff|ffffff)"' ./public/images/icons || echo "CLEAN: zero white backdrop rects"; grep -L 'viewBox=' ./public/images/icons/*.svg || echo "CLEAN: all SVGs retain viewBox" CLEAN: zero white backdrop rects
CLEAN: all SVGs retain viewBox How to Prevent This Error From Recurring
Always preview transparent PNGs and SVGs on BOTH #F7F7F5 light and #111111 dark cards
Halos and missing strokes are invisible on a white Figma artboard—dual-surface previewing catches 100% of edge defects instantly.
Never enable SVGO removeViewBox in design-system repos
Stripping viewBox breaks responsive CSS width/height scaling across Tailwind utility classes.
Automate SVG hygiene in coding agents with Skill 30
Install Skill 30 (SVG Optimization & Icon System) so Claude Code and Cursor clean every exported SVG automatically.
Troubleshooting FAQs
- Why does SVGO sometimes break responsive icon scaling?
- Older SVGO presets enabled removeViewBox by default, stripping viewBox and leaving icons stuck at fixed pixel dimensions. Always verify viewBox remains present after optimization.
- Can I save OpenAI GPT-Image-2.6 transparent cutouts as WebP to cut file size?
- Yes. Encoding RGBA PNGs to WebP via sharp with alphaQuality: 95 cuts file size 50–70% while keeping transparent edges razor-clean across every modern browser. OpenAI shut down the GPT Image 1 API model on October 23, 2026; GPT-Image-2.6 is its current replacement and still accepts background: "transparent".
- How do I fix an existing white halo on a photo I cannot regenerate?
- In Photoshop or Affinity Photo, run Layer -> Matting -> Defringe (1–2 px) or contract the alpha mask by 1 pixel with a 0.5px feather to trim the white fringe cleanly.
- Should multi-color brand illustrations also replace strokes with currentColor?
- No—apply currentColor strictly to monochrome UI icons. For multi-color brand illustrations, map accent colors cleanly to semantic CSS custom properties like var(--accent-signal).