DEV Community

NullPointerZen
NullPointerZen

Posted on

Flattening a cutout to white burns 7% of its pixels

Cutting the background out of a batch of shop photos is the easy part — pick a model, click once, done. What actually stopped me was the next step. The panel offers transparent formats, and it also lets you set the canvas to white and export that. I sat looking at the buttons for a while with no idea which one was the right answer. It took getting it wrong once to see the question is backwards: you don't ask this at export time, you ask where the image is going next. Short version up front — keep transparency and export WebP or PNG, flatten to white JPG only at the very last step for places that can't read an alpha channel, and don't pick GIF for a still.

I'm not from a CS background, so what follows is what I ran into, not how it works underneath.

Three delivery forms of one cutout

Same result exported three ways, three completely different uses. Transparent PNG or WebP is for whoever does layout — they choose the background later. Flattened white JPG is for places that can't recognise an alpha channel: legacy upload forms, images going into a Word document, anywhere you're worried it'll render as a black box on the other end. Composited onto a scene locally is the finished piece, ready to post.

The trap is the middle one. I counted the alpha channel on this image and roughly 7% of the pixels are neither fully transparent nor fully opaque — the highlight along the cap, the frosted-glass falloff, the fine edge of a fingernail all live in there. The entire purpose of that soft edge is to blend with whatever is behind it, so the instant you flatten onto white, it is married to white. Put it on a dark card later and that ring of white-blended pixels shows up honestly as a white fringe, and you can't remove it in post because the original transparency was discarded during the flatten.

There's a quick way to find out whether somewhere accepts transparency: throw a transparent image straight at it. Background goes white, it filled with white. Background goes black, it dropped the alpha channel and backed it with black. The second one is nasty because everything looks fine in your own preview and only breaks on their side. When you hit that, flatten to white and give it that, rather than hoping it gets smarter.

There's a format trap too. Of the transparent download options WebP is marked recommended and PNG works fine, and both keep the full 0–255 range of transparency. I tried the GIF option and backed straight out: it's tagged "server", so the file has to leave the machine to be processed, and GIF transparency is one bit — fully on or fully off. That 7% of soft edge gets hard-cut into all-or-nothing and you get jaggies around the whole subject. Animation is another conversation; for a still there's no reason to choose it.

Retouch and multi-background compositing panel

The compositing is done locally — background can be transparent, a solid colour or an image, there's a "set to white" shortcut next to the colour, and the subject and background layers move and scale independently. The part that saves me is the "verify download result" at the top: it shows you the composited output before you download it. My own mess came from hitting download directly and only finding out once the image was on the page.

So one rule now: export the transparent original and keep it, then flatten copies per destination. Copies are disposable, the original isn't. Sounds obvious written down, but I only started doing it after wasting an afternoon. The tool is ImgIng, imging.ai.

Top comments (0)