Passport and visa photo rules are written in millimetres: "35 × 45 mm". Image files don't have millimetres. They have pixels. If you're building a photo tool, or just trying to make a photo that a print shop or an upload form will accept, you need to convert between the two.
The bridge is DPI (dots per inch), and the math is short.
The formula
There are 25.4 mm in an inch. So:
pixels = mm ÷ 25.4 × DPI
For a 35 × 45 mm photo:
| DPI | Width | Height |
|---|---|---|
| 300 | 413 px | 531 px |
| 600 | 827 px | 1063 px |
300 DPI is the usual target for photo prints. 600 is overkill for most printers but harmless.
In code:
const mmToPx = (mm, dpi = 300) => Math.round((mm / 25.4) * dpi);
mmToPx(35); // 413
mmToPx(45); // 531
The same formula works for any size: 2 × 2 inch (US) at 300 DPI is simply 600 × 600 px, and 3.5 × 4.5 cm is the same as 35 × 45 mm.
DPI in the file doesn't change the pixels
This trips up a lot of people. A JPEG can store a DPI value in its header, but that number is only a hint for printing. It doesn't add or remove any pixels.
A 413 × 531 px photo tagged as 72 DPI and the same photo tagged as 300 DPI contain exactly the same image. The only difference is the size a printer will use by default:
- at 300 DPI: 413 px ÷ 300 = 1.38 in = 35 mm wide
- at 72 DPI: 413 px ÷ 72 = 5.7 in = 146 mm wide
So when a form says "300 DPI", check whether it actually reads the DPI tag, or only cares about pixel dimensions and file size. Many online forms only check the pixels and the KB.
Crop to the right shape first
35 × 45 is a ratio of 7:9. A phone photo is usually 3:4 or 9:16, so you have to crop before you resize, or the face gets stretched.
// Largest 7:9 rectangle that fits in the image, centered
function cropRect(srcW, srcH, ratioW = 35, ratioH = 45) {
const target = ratioW / ratioH;
let w = srcW;
let h = Math.round(w / target);
if (h > srcH) {
h = srcH;
w = Math.round(h * target);
}
return { x: Math.round((srcW - w) / 2), y: Math.round((srcH - h) / 2), w, h };
}
Then draw that rectangle onto a 413 × 531 canvas with drawImage(img, x, y, w, h, 0, 0, 413, 531). In a real tool you'd let the user move the crop box, because the face is rarely dead center. Most passport rules also want the head to take up a specific share of the height, so a centered crop is only a starting point.
Printing several on one sheet
Print shops usually print on 4 × 6 inch (about 102 × 152 mm) paper. In landscape, that fits 4 photos across (4 × 35 = 140 mm) and 2 down (2 × 45 = 90 mm), so 8 photos with a little room for gaps and cutting lines.
At 300 DPI the sheet is 1800 × 1200 px. Place each 413 × 531 photo with a few pixels of white space between them and you have a print-ready file.
Try it
PixelKaro's passport size photo maker does the crop, white background and multi-copy sheet in the browser, and the DPI print size calculator does the mm/inch/pixel conversion for any size. Nothing is uploaded.
What photo size requirement has given you the most trouble?
Top comments (0)