ID photo background changer
Replace an ID photo background locally in the browser: upload a JPG/PNG/WebP, flood-fill the background from the border pixels, paint it red / white / blue / grey, rescale to common ID sizes (295×413, 413×579 …) with contain or cover fitting and export a PNG — plus the pixel count and 300 DPI print size for upload checks.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Size and colour reference
Check the size first: 1 inch 295×413, 2 inch 413×579, small 2 inch 413×531, large 1 inch 390×567, US visa 600×600 — or type width x height.
Target size: 295 × 413px (1 inch) Background: #ff0000 Total pixels: 121835 Print size at 300 DPI: 24.98 × 34.97mm The background swap and resizing run live on the canvas below; this text only reports the parameter values.
Result
The canvas is exactly what gets exported: background pixels painted with the chosen colour, then scaled to the selected size. Foreground pixels are left untouched — no smoothing, no beautify, no edge feathering.
A pixel counts as background when its Euclidean distance to the border sample is within the tolerance. 20–40 is enough for a flat background; raise it to 60–90 for gradients or JPEG noise, but too high will erase light clothing.
Upload an ID photo to see the background replacement and resize here
What this tool does
- When a form demands a white background, 295×413 px and under 100 KB, swap the blue background here, resize to the 1-inch spec and export a PNG before compressing it.
- Produce red / blue / white variants of the same original photo for a CV, exam or visa application by switching the colour and exporting again — no need to retake the photo.
- Check print sizing: type the size to see the pixel count and the millimetre size at 300 DPI, so a 295×413 photo is not printed 10 cm wide by mistake.
Example
Input
1inch (background set to blue)
Output
Target size: 295 × 413px (1 inch) Background: #438edb Total pixels: 121835 Print size at 300 DPI: 24.98 × 34.97mm The background swap and resizing run live on the canvas below; this text only reports the parameter values.
The input accepts a preset id or widthxheight, and colour names are normalised to #rrggbb (blue = #438edb). The pixel-level replacement and resize happen on the page: upload an image, the canvas shows the result and the stats report the background and subject pixel counts.
Frequently asked questions
How is the background replaced?
The average colour of the image border is taken as the background sample, then a breadth-first flood fill spreads from all four edges: pixels within the tolerance (Euclidean distance to the sample) count as background and are painted with your colour (red #ff0000, white #ffffff, blue #438edb, grey #c0c4cc or a custom #rrggbb). Pixels the fill never reaches — the subject, hair, clothing — are left untouched. The tolerance can be tuned from 0 to 160.
Why is some background left over, or why did my shirt get erased?
The flood fill only accepts pixels close to the sampled background colour. Raise the tolerance for gradients, shadows or JPEG noise; but a high tolerance will also erase light clothing, so keep it low and shoot against a flat background instead. There is no AI matting, no edge feathering and no brush touch-up: hair strands and semi-transparent edges keep their original pixels (they may keep a rim of the old colour).
What do contain and cover do?
contain scales the photo proportionally into the target canvas and pads the rest with the chosen colour, so no part of the subject is cropped — good when the head-to-shoulder ratio is already correct. cover scales up to fill the canvas and centre-crops, leaving no padding but cutting the top/bottom or sides when the aspect ratio changes a lot, so compose the crop first. Both resample pixels to the target size.
Which sizes are supported? Can I use my own?
Built-in presets: 1 inch 295×413, small 2 inch 413×531, 2 inch 413×579, large 1 inch 390×567 and US visa 600×600; you can also type widthxheight such as 413x531. The pixel cap is 40 million — above that you get a size error. Millimetre sizes are reported at 300 DPI, the common print reference for ID photos in China.
Is the photo uploaded to a server?
No. The image is decoded by the browser into a canvas and the flood fill, painting and resizing all run in local memory with no network requests; the export is a PNG the browser generates itself, and everything disappears when the page closes.