Photographic visual for Two Edge Faults
Two Edge Faults

The two edge faults

Most bad PNG-to-JPG edges come from one of two faults in the edge pixels. They look alike and need opposite fixes, which is why this converter works out which one it has first.

The edge band

A cut-out or anti-aliased PNG has a thin band of part-covered pixels around every shape: alpha between a few percent and nearly opaque. When the PNG is put on a matte, each of those pixels is mixed with the matte in proportion to its coverage. If its own colour is right, the edge looks smooth. If its colour is wrong, the band shows as a rim — and on most converted logos, it is wrong in one of two ways.

Fault one: premultiplied colour

Some export pipelines store each pixel's colour already multiplied by its alpha. A 50%-covered orange pixel is written as half-brightness orange with alpha 50%. A program that then treats it as straight colour multiplies by the alpha a second time, and the edge comes out twice as dark as it should: a grey or black rim on white.

The repair is arithmetic: divide the colour back out by the alpha. It makes edge pixels lighter. The converter detects the fault by checking whether, across the band, no channel ever exceeds its alpha — a pattern that straight colour almost never shows and premultiplied colour always does.

Fault two: borrowed colour

A subject cut out of a photograph or a coloured backdrop keeps some of that backdrop in its edge pixels: the camera or the renderer blended them before anyone removed the background. Cut out of black, the band is darkened; cut out of white, it is lightened. On a matte of a different colour the borrowed colour shows — a dark rim on white, a white halo on black.

The repair is a lookup, not arithmetic: each edge pixel takes its colour from the nearest solid pixel of the artwork, searching outward in rings, and keeps its own coverage. Whether that makes the edge lighter or darker depends on what the backdrop was.

Why the order matters

Questions

Why is there a grey outline around my logo on white?
Either the edge pixels were stored already multiplied by their own transparency, so they are too dark, or they still carry the dark background the logo was cut out of. Both look like a grey rim on white; the converter finds which one it is before repairing it.
Why is there a white outline on a dark background?
The artwork was cut out of a light background and its edge pixels still hold some of that light. The same borrowed-colour repair fixes it: each edge pixel takes its colour from the nearest solid pixel of the artwork.
Does the repair change the solid parts of my picture?
No. It touches only pixels between 3% and 97% coverage — the edge band — and leaves fully solid and fully clear pixels exactly as they were.