Is the Face in This Selfie Too Small? A Python Minimum-Face-Size Check Before a Malfoid AI Upload
A portrait tool can accept a photo because "there is a face in it" and still give you a mushy, unlike-you result. The usual cause, when the file is otherwise sharp and untilted, is a wide shot: the head is a small patch of a room, a mirror, or a group, and the generator has only a few dozen pixels of identity to work with.
This is a pre-upload check for that case, written for Malfoid AI, an independent unofficial studio that makes a still 3:4 Female Malfoy / Fem Draco portrait from one photo of an adult, or without a photo. A portrait is $4.99 and spends 2 credits, at a 1K setting. There is no video, no prompt box, and no clip length. The photo-requirements guide already asks for one adult and a visible face; this script asks a more specific question: is the face large enough in the frame?
It is not a JPEG-quality check, not a motion-blur check, and not a head-tilt check. Those are different failure modes. This one measures three numbers on the file you are about to upload:
- face height in pixels
- face-to-frame ratio (face height / image height)
- inter-ocular distance (IOD), from the two eye centres, when the eyes can be found
The thresholds were locked on eight synthetic sitters (shapes only: platinum hair, an oval face, academy clothes; no real photograph, no studio showcase, no customer render) placed at six distances and crops. The script, tests, and bench live next to this post as face_size.py, test_face_size.py, and bench_face_size.py.
Why "there is a face" is not enough
A 12-megapixel phone selfie of you at the far end of a corridor still contains a face. A face detector will often find it. The face itself may only be 50 pixels tall. After the studio's still 3:4 crop and a 1K result, that is not much identity to keep. People describe the result as mushy, or as "not really me," and then blame the model. Sometimes the model never had a large enough face to start with.
The check is intentionally conservative. If the detector cannot find a face at all, the file is labelled too_small (a retake), not passed in silence.
How the measurements are taken
The script does not use the construction landmarks at test time. It:
- Finds the largest skin-coloured blob near the centre of the frame, excluding platinum-bright hair so the hair oval does not win, and reports that blob's height as
face_height_px. A one-pixel pad only — the height should stay close to the skin region, not a padded box. - Divides that height by the image height for
face_to_frame. - Looks for a pair of bright-sclera blobs in the mid-upper face, one per half, and takes the distance between their centroids as
iod_px. Raw edge energy is a bad way to find the eyes: it peeks at the hairline. Sclera, on an open eye, is much brighter than local cheek skin.
On a far or tiny sitter the sclera is only a few pixels across, and IOD is withheld. Height and ratio still run.
# Locked on the 8-sitter distance bench, 2026-11-18.
T_HEIGHT_FAIL, T_HEIGHT_WARN = 110.0, 170.0 # pixels
T_RATIO_FAIL, T_RATIO_WARN = 0.11, 0.18
T_IOD_FAIL, T_IOD_WARN = 36.0, 58.0 # pixels
def classify(face_h, ratio, iod):
if face_h is None or ratio is None:
return "too_small"
fail = (face_h < T_HEIGHT_FAIL) or (ratio < T_RATIO_FAIL)
if iod is not None:
fail = fail or (iod < T_IOD_FAIL)
if fail:
return "too_small"
warn = (face_h < T_HEIGHT_WARN) or (ratio < T_RATIO_WARN)
if iod is not None:
warn = warn or (iod < T_IOD_WARN)
return "small" if warn else "ok"
A file fails if any fail threshold is crossed, and warns if any warn threshold is crossed without a fail.
The bench
Each of the eight sitters was drawn at 768×1024, then placed in six conditions on the same canvas: a tight close-up (face-to-frame about 0.78), the original head-and-shoulders frame, a 0.70 "step back," a 0.45 modest wide shot, a 0.28 far shot, and a 0.16 tiny face in the corridor. Each image was also saved as JPEG quality 95 and as a 95% down-up bilinear resample, so the thresholds are not only true on clean PNGs. That is 144 files.
Oracle means on the PNGs (known geometry, not the detector): face heights 800.00 / 310.00 / 217.00 / 139.50 / 86.80 / 49.60 px; ratios 0.7813 / 0.3027 / 0.2119 / 0.1362 / 0.0848 / 0.0484; IOD 278.71 / 108.00 / 75.60 / 48.60 / 30.24 / 17.28.
Measured means on the same PNGs: heights 807.12 / 313.00 / 219.88 / 142.38 / 89.12 / 51.88; ratios 0.7882 / 0.3057 / 0.2147 / 0.1390 / 0.0870 / 0.0507; IOD 278.33 / 108.00 / 72.28 / 45.09, and no IOD on the far and tiny sets. Height relative error on PNG was mean 0.021, median 0.014, p95 0.048 (n=48). IOD relative error was mean 0.032, median 0.001, p95 0.201 (n=32).
With the thresholds above, 3-class accuracy was 144/144 = 1.000. Every tight, full, and mid-0.70 file was ok (72 of them, including JPEG and down-up). Every modest-0.45 file was small (24). Every far and tiny file was too_small (48). Binary retake — too_small versus small or ok — was tp=48, fp=0, tn=96, fn=0, precision 1.000, recall 1.000. Median analyse time was 13.22 ms. Seven tests in test_face_size.py passed.
Running it
python face_size.py selfie.jpg
python face_size.py selfie.jpg --json
The process exits 0 on ok or small, 1 on too_small, and 2 if the file is missing. --json prints the face box, the three measurements, the label, and a reason (measured or no_face). You can drop the same file into a pre-upload hook next to a blink check or a tilt check; this one only cares about size.
A short reading of the table, if you would rather eyeball a crop than run the script: on a 1024-pixel-tall 3:4 frame, a face about 310 pixels tall (ratio 0.30, IOD about 108) is a normal head-and-shoulders upload and passed every variant in the bench. A face about 140 pixels tall (ratio 0.14, IOD about 45) is the warn band — that was every modest-0.45 sitter, including JPEG q95 and the 5% down-up. A face under about 90 pixels tall (ratio under 0.09) was a retake, even when IOD could not be measured. The far-0.28 sitters had a mean measured height of 89.12 px; the tiny-0.16 sitters, 51.88 px. Both sets were 24/24 too_small.
IOD is the finicky one, and it should be. The detector looks for sclera, not for a generic dark blob, because a hair swoop or a dark glasses lens will also make a dark blob. On the full-frame seed-1 sitter, measured IOD was 108.00 against an oracle of 108.00. On the modest sitters it was 45.09 against 48.60, still inside the warn band (36–58). Below roughly 90 px of face height the sclera is too small to trust, and the script would rather say "I do not have an IOD" than invent a number that would push a bad crop into ok. Height and ratio already catch those frames.
This is a size check, not a quality guarantee. A large, motion-blurred, beauty-smoothed, or eye-occluded face can still be a poor upload. Use it as the first gate, then look at the photo itself. And if you do not want to upload a photo at all, the studio also sells a portrait without one, at the same $4.99 / 2-credit price; that path does not need this script.
What to do with a warning or a retake
too_small means crop in, or retake closer, until the head fills more of the frame. A modest wide shot in this bench (ratio about 0.14, height about 142 px, IOD about 45) is the warn band: usable, but a closer crop is safer. The original 3:4 head-and-shoulders sitter (height about 313 px, ratio 0.31, IOD 108) is comfortably ok, which is the kind of photo the photo-requirements page is describing.
The script does not upload anything. It does not talk to the studio. It prints the three numbers and a label. Guest checkout on malfoidai.com is still $4.99 for one still; packs, if you want them, are $13.99/30, $35.99/100, and $59.99/200, account required, one-time, and the pricing HTML says "Credits never expire." A delivered portrait is not refunded as a change of mind, so a five-millisecond pre-check is cheaper than a retake you have already paid for.
Use your own photo, or a photo of an adult who agreed. The result is unofficial fan art, not an official character image, and not a verified likeness. This post is not affiliated with the books, films, author, publishers or studios.
Top comments (0)