Transparent PNG alpha — what the fourth channel really stores
A transparent PNG is not a picture with holes in it. Every pixel still carries three colour bytes; a fourth says how much of what sits behind it shows through. Most edge trouble blamed on “bad transparency” is that byte meeting a background it never matched.
The fourth byte
A transparent PNG uses colour type 6: an R, G, B triple plus one alpha sample per pixel, at 8 or 16 bits. Per the PNG specification, 0 is full transparency and 2bitdepth−1 full opacity, intermediate values compositing against the background. The spec is explicit about colour too: “PNG does not use premultiplied alpha.”
That matters: a pixel at 30% opacity stores its full colour, not 30% of it. Straight alpha, also called unassociated. One decision in a 1996 format is behind most of this page.
Where the alpha in this file comes from
The keyer converts each pixel to YCbCr, measures its distance from the key colour in the Cb/Cr plane (luminance for a neutral backdrop) and turns that distance into alpha: 0 at or below the lower threshold, 1 at or above the upper one, a straight line between.
The lower threshold is (tolerance / 100) × 118 for a colour key, × 150 for a neutral one: default tolerance 25 opens a band 29.5 units wide on green, 37.5 on a white wall. A positive edge widens the ramp by (edge / 100) × 46 units for colour, 60 for neutral; a negative edge pushes the threshold inward instead.
At the default edge of 0 the two thresholds coincide and the matte is hard: alpha is only ever 0 or 255, and a default export has no partially transparent pixels at all. Fractional alpha exists only where you asked for a soft edge — at edge +100 with tolerance 25 on green the ramp runs 29.5 to 75.5 units, and that span is the whole soft edge.
Alpha is a threshold result, not a fade. In the shadow sweep, a backdrop at 65% brightness sits 29.3412 units away and lands on alpha 0 at tolerance 25; the same backdrop at 60% sits 33.5337 away and lands on 255, fully opaque and not keyed at all. Raise tolerance to 50 and both go to 0.
Why one file looks white here and dark there
Compositing is one line of arithmetic: out = C × α + B × (1 − α), where C is the colour stored in the pixel and B is whatever is behind it. At α = 0.1, ninety per cent of what you see is the background. Nothing in the PNG records what that background should be — the file is a promise, not a finished picture.
So one export can look fine on a checkerboard, pale on white and grimy on near-black, with no change to the file. The preview on the tool has Checker, Dark and Light buttons for exactly this: flip the frame between backings and watch the outline. A fringe on both is colour in the pixel; a fringe on one is the backing showing through coverage you did not mean to create.
That is arithmetic, not a measurement: everything here is measured on synthetic 320×240 fixtures against a binary ground truth.
Why a clean matte can still show a white rim
Four things produce the white or dark rim people report; only one is in the file.
- Straight alpha read as premultiplied. A compositor expecting premultiplied data computes
C + (1 − α) × Binstead ofC × α + (1 − α) × B— brighter than intended, a pale halo. The reverse mistake darkens it. The PNG is unambiguous; the reader is not. - Flattening on white. Convert to JPEG, “save for web”, most thumbnailers and plenty of upload pipelines fill transparency with white first. A pixel at α = 0.1 then picks up ninety per cent white — a fringe that was never in the PNG.
- A soft pixel keeps its old colour. This keyer writes alpha, not a replacement colour: the source RGB goes back unchanged unless you move spill, which only pulls the dominant channel toward the brighter of the other two. A feathered pixel at low alpha stays green-tinted — dull over dark, pale over light.
- A fully transparent pixel still carries three colour bytes. Software that ignores alpha, or a JPEG screenshot, displays them: usually green, sometimes black. Neither is what the file means.
What actually gets written
Export makes a canvas at the source’s full pixel size, clears it, draws the frame, keys it in place and encodes once as PNG. Nothing is composited onto white and nothing is stamped on. Each pixel keeps the source RGB — spill-adjusted if you asked — with alpha as round(α × 255), one of 256 levels.
The same pixels go into a PNG sequence’s frames; the transparent WebM path is a different route with different losses, covered in PNG sequence vs transparent WebM and transparent WebM explained.
Checking a file before you hand it over
Put the result on Dark, then Light, and watch the outline rather than the middle of the subject. Visible on both means colour: move spill, or trim with a negative edge. Visible on one means coverage: lower the feather. If a destination shows it identically on black and white, its alpha was flattened on the way in.
Keep the PNG as master. Once a copy has been through a JPEG or a web export, the fourth channel is gone.
When this does not work
- The subject is genuinely semi-transparent. Hair, smoke, glass and motion blur give pixels that are partly subject, partly backdrop, and alpha has one number per pixel: it cannot say which is which. See which edge problem you have before reaching for a slider.
- You need a soft edge that also changes colour. Feathering gives coverage without a new colour, so soft edges keep their green cast. Spill suppression is the only colour lever, and no sweep measures how far it goes.
- The destination ignores or flattens alpha. Nothing in your control; the file is correct and the pipeline is not.
- The source was already heavily compressed. The edge pixels’ colour is unreliable before the key runs, and straight alpha faithfully preserves unreliable colour.
- Backdrop brightness crosses the threshold mid-frame. A shadowed screen can sit at alpha 255 on one side and 0 on the other — the byte flips, it does not fade. Light the screen rather than chasing it with tolerance.
- You want 16-bit alpha. The canvas here is 8 bits per channel, so the file is 8-bit; the format allows more, this pipeline does not produce it.
- You need per-pixel hand work. There is no brush and no matte painting. Alpha comes from colour distance and nothing else.
- You are judging the result from a thumbnail. Thumbnailers composite, usually on white, at a scale where a two-pixel rim becomes a border.
Where the numbers come from
Thresholds and the feather and trim scales come from the keyer in the reference repository; the alpha column above is from its shadow sweep on a synthetic 320×240 fixture, not real footage. The write-up is archived at doi.org/10.5281/zenodo.22916767; the format rules are the PNG specification. For a photo, the photo walkthrough covers the same export.