← All guidesHome› Image Guides › Border Trimming

Trimming White Borders: Why a Two-Pixel Line Survives, or Doesn't

Published 2026-11-20Updated 2026-11-202,375 wordsBased on the PicCalc tool's implementation

Automatic border trimming looks like magic the first time it works and looks broken the first time it does not. Both reactions come from the same fact: the trimmer is a small, deterministic scanner, not a model that understands your image. It samples the border colour, then walks inward until it meets something that is not that colour. Everything it does — and everything it fails to do — follows from how those two steps are implemented.

This page documents the procedure used by our Trim Borders tool, including the parts that are easy to trip over: an averaged corner colour, a scan stride, and a tolerance test that works per channel rather than by distance.

What the trimmer is looking for

The goal is a rectangular crop that removes rows and columns which contain only the background. For a scanned document on a white page, for a product photo shot on a seamless white background, or for a screenshot with a wide empty margin, this is exactly the right operation. For anything else — a photo with a gradient sky at the edge, a card with a drop shadow, a page photographed at an angle — it is an approximation that may stop early or cut too much.

Two settings change the definition of "background": the colour it compares against, and how different a pixel may be before it counts as content. Both have defaults that suit the common case and both need adjusting for the uncommon one.

The corner sample and its blind spots

By default the reference colour is the average of the four corner pixels. Averaging is a compromise. It handles the case where one corner is slightly dirty, and it fails when the corners are genuinely different colours.

  • A card with two-tone background: top corners from one panel, bottom corners from another. The average lands between them and matches neither, so nothing is trimmed.
  • Rounded corners on a screenshot: the corner pixels are the page behind the card, not the card border. The average picks up that outer colour, and the scan stops at the card's edge.
  • A scan with a dark strip along one edge: one corner is much darker, dragging the average away from white; the white border on the other three sides no longer matches.

The second sample mode fixes all three: pick the border colour directly from the image. It costs one click and removes the entire class of "the corners lied" failures. If trimming does nothing on the first attempt, this is the first thing to try — before touching tolerance.

Roughly 240 checks per row

A row is considered background when every sampled pixel in it matches the reference colour. The word "sampled" is doing a lot of work there. Checking every pixel of a 4000-pixel row, on every row of a 3000-pixel image, is twelve million comparisons before anything is cropped; instead the scanner uses a stride:

stride = max(1, floor(width / 240))

So it looks at roughly 240 positions per row regardless of image width. The stride is invisible in the interface, and it explains the single most confusing result this tool produces: a thin line of content that survives the trim, or a thin border that does not get removed.

Image widthStrideSamples per rowChance a 1 px line is hit
240 px1240100%
1200 px5240~20%
2400 px10240~10%
4000 px16250~6%

The probability scales with the thickness of the feature: on a 1200-pixel-wide image, a five-pixel line has roughly an 80% chance of being sampled somewhere and stopping the walk, while a one-pixel rule is mostly invisible. This is not a bug to be fixed by adding more samples; scanning every pixel would make the tool unusable on phone photos. It is a limitation to design around: if you need a hairline preserved exactly, crop by hand.

The same stride applies vertically when scanning columns, using the image height. A tall, narrow image with a thin horizontal border is therefore more likely to trim correctly than a wide one with a thin vertical border.

What tolerance actually compares

Tolerance is a per-channel allowance, not a distance. A pixel matches when each of red, green and blue is within the tolerance value of the reference:

match = |r - r0| <= t && |g - g0| <= t && |b - b0| <= t

That is a cube in colour space, not a sphere. At the default tolerance of 18, a pixel may differ by 18 in every channel and still count as background; the corner of that cube is about 31 units away in straight-line distance. The practical effect is that colour casts are handled more generously than expected, while a single-channel difference — a slightly blue shadow, for example — can fail even when the colours look identical to the eye.

ToleranceBehaviourTypical use
0Exact match onlyFlat PNG exports, synthetic images
8–12TightClean scans, screenshots
18 (default)ModerateJPEG photos with mild noise
30–45LooseCompressed scans, faint gradients
60–80Very looseNear-white content will be eaten

The failure is asymmetric. Too low and the tool reports that nothing was trimmed, which is obvious and harmless. Too high and it quietly removes pale content — light grey text, thin table rules, the pale edge of a shadow — which is much easier to miss until the file is published. When in doubt, start low and raise it in steps, checking the preview between attempts.

Failure modes, and what they look like

Nothing is trimmed

The border does not match the reference within tolerance. Causes, in order of likelihood: gradient background, drop shadow, averaged corners from a mixed background, scanner noise above the tolerance. Fix: switch to "pick a colour", sample a true border pixel, then raise tolerance gradually.

Only some sides are trimmed

The walk stops independently on each side at the first row or column that contains a sampled non-background pixel. A watermark, a page number, a punch hole, or a shadow along one edge is enough to stop that side while the other three trim normally. The result is an off-centre crop that looks deliberate and is not.

Content is clipped

Tolerance is wide enough that pale content matches the background. The symptom is a crop that looks correct in the preview and has lost the top of a letter or a light rule. Lower the tolerance and compare the before and after dimensions: if the crop is smaller than the visible border, something inside was eaten.

Edges remain slightly dirty

A soft shadow does not have a hard boundary, so the last matching row still contains a faint tint. This is where the rounded-corner mode helps, because it clears the corner wedges left by anti-aliasing; for straight edges, a small manual crop of a few pixels finishes the job.

Rounded corners and scan edges

The rounded mode exists for a specific visual pattern: a screenshot of a card or dialog with rounded corners, exported on a solid background. After a straight trim, four curved wedges of background remain in the corners. The rounded mode removes them, so the result looks like a clean rounded rectangle rather than a rectangle with white notches.

It does not change how the straight edges are detected. If the side borders are gradients, enabling the rounded mode will not fix them. Use it as a finishing pass, not as a substitute for a correct reference colour.

When to crop by hand instead

Automatic trimming is the right tool when the border is genuinely uniform and the content is clearly separated from it. Manual cropping wins in four situations:

  • Skewed scans. A page photographed at a slight angle produces a border that is not axis-aligned; a rectangular crop cannot follow it. Rotate or straighten first.
  • Hairline content. As the stride table shows, one- or two-pixel features near the edge may be missed. Crop to keep them.
  • Gradients and shadows. There is no tolerance that separates a soft shadow from the background without also removing pale content.
  • Intentional asymmetric margins. A design with a wide left margin and a narrow right one is not a defect; trimming will destroy the composition.

The Crop tool gives you exact numeric control and a live preview, which is slower but predictable. A reasonable default is to attempt the automatic trim first, inspect the result at 100%, and fall back to manual cropping when the four sides do not behave consistently.

Choosing a tolerance from the file, not from habit

The default of 18 is a compromise, and on many files it is the wrong compromise. The right value follows from how the border was produced, because each source leaves a different amount of noise around what is nominally one colour.

  • PNG screenshots: 0–6. The border really is one value, so a wide tolerance only risks eating content that happens to be pale.
  • JPEG screenshots or exports at quality 85 or above: 8–14. Block noise around a flat white margin typically moves each channel by a handful of levels.
  • JPEG at quality 60–75, or a re-saved file: 14–24. Artefacts spread further, especially next to text.
  • Scanned paper: 12–24. The paper texture varies across the sheet, and the scanner adds its own noise on top.
  • Anything with a gradient or a shadow: none of these values work. Crop by hand.

There is a practical way to find the value without guessing. Pick the colour manually, set tolerance to 0, and note the left/right/top/bottom numbers in the result line. Raise the tolerance in steps of 4 and watch the numbers. A correct setting usually produces a jump: the removed amount stays small, then suddenly matches the real margin. If the numbers creep upward gradually and never settle, the border is not uniform and the scan will either under-trim or eat content, whichever you choose.

A corner average that fails, with the arithmetic

Take a photograph framed with sky at the top, grass at the bottom and a white page between them. Suppose the top-left corner samples (135, 206, 235), the bottom-left (85, 107, 47), and the two right corners (250, 250, 250). The tool averages each channel across all four: red (135 + 85 + 250 + 250) / 4 = 180, green (206 + 107 + 250 + 250) / 4 = 203.25, blue (235 + 47 + 250 + 250) / 4 = 195.5. The reference becomes roughly (180, 203, 196) — a teal that appears nowhere in the picture.

With that reference, the white page differs by about 70 levels in red and 47 in green, far outside any sensible tolerance, so nothing is trimmed and the result line reports zeros on all four sides. Switching to "pick a colour" and choosing the actual page white fixes it immediately. The lesson generalises: whenever the four corners are not the same material, the automatic reference is meaningless, and the manual colour is not an advanced option but the correct one.

Trimming a set without a batch mode

There is no queue here, so a set of forty product shots is forty passes. The work is still consistent if the inputs are: settle the tolerance and colour on the first file, write down the four removal numbers, then compare them on the next few. If the numbers are stable to within a few pixels, the set was shot consistently and the same settings will hold. If they differ wildly — 40 px on one side for one file, 180 for the next — the set is not uniform, and no single setting will serve it; sort the files by removal amount and treat them in groups.

One trap is worth naming. Trimming changes the image dimensions, so a later resize to a fixed box will scale each file by a different factor. For a marketplace that requires identical frames, trim first and then apply the same crop and the same resize preset to every file, in that order. Applying resize first and trimming afterwards is what produces a set where the products look slightly different sizes.

Frequently asked questions

Why was nothing trimmed?The border does not match the averaged corner colour within tolerance — usually a gradient, a shadow, or mixed corners. Pick the border colour manually first.
Why did it cut into my content?Tolerance is too wide, so pale content near the edge counts as background. Lower it and re-run; compare the output dimensions against the visible border width.
Why is a thin line still there?The scanner samples about 240 positions per row, so a one- or two-pixel feature can fall between samples. Crop manually if it must be preserved.
Can it straighten a skewed scan?No. Rotation and perspective correction are separate operations; trimming assumes an axis-aligned border.
Does trimming change the remaining pixels?No. The crop is a pixel-exact region copy; only the export format re-encodes the result.

Try it on a scan

Open Trim Borders, start at tolerance 12, and raise it only if the preview shows an untouched border. If one side refuses to trim, switch to picking the border colour.