I built a portfolio page with my face in the middle of the hero. It follows your mouse with its eyes, blinks now and then, looks surprised when you click it, and puts on sunglasses when you hover the Contact button.
It looks like 3D. It isn't. It is 14 pictures of the same head, made with an AI image tool, and a small script that picks the right one at the right moment.
I've made the project public, so you can do the same with your own face. Or, if you'd rather not, turn yourself into a lion, a robot or a cartoon character. This guide covers every step and every prompt.
Try it live: ahmadalghawi.github.io/living-portrait · The code: github.com/ahmadalghawi/living-portrait
What you need: one good photo of yourself, an account with an AI image tool that can edit photos (Gemini or ChatGPT both work), Node.js, and about an hour.
How it works
Every picture shows the same head, the same size, in the same spot, with the same light. Only one thing changes per picture: where the eyes look, whether they are closed, or the expression.
File in public/ | What the face does |
|---|---|
user-face.png | Resting face, looking straight ahead |
user-face-up.png | Eyes look up |
user-face-down.png | Eyes look down |
user-face-left.png | Eyes look left |
user-face-right.png | Eyes look right |
user-face-upleft.png | Eyes look up and left |
user-face-upright.png | Eyes look up and right |
user-face-downleft.png | Eyes look down and left |
user-face-downright.png | Eyes look down and right |
user-face-closed.png | Eyes closed (used for blinking) |
user-face-wink.png | A wink with a smile |
user-face-shock.png | Surprised: eyebrows up, mouth open |
user-face-angry.png | Annoyed: eyebrows down, lips pressed |
user-face-sunglasses.png | Wearing dark sunglasses |
The script in index.html watches your mouse and clicks. When the mouse moves up and to the left, it shows user-face-upleft.png. Every few seconds it plays a quick blink with user-face-closed.png. Click the forehead and you get the angry face. It also draws the picture on a soft WebGL sheet that bends slightly, so the skin seems to move instead of jumping from photo to photo.
That is why the rules below matter so much. If one picture is a little bigger or sits a little lower, the head jumps when the script swaps it in.
Step 1: Get the project running
git clone https://github.com/ahmadalghawi/living-portrait.git
cd living-portrait
npm install
npm run dev
Open http://localhost:3000. You should see my face. Move your mouse around it and click it a few times to see what each picture does.
Step 2: Take one good photo
The AI copies what it sees, so start with a clean photo:
- Face the camera straight on, with your head level.
- Soft, even light from the front: a window in daylight is perfect. Avoid hard shadows on one side.
- A neutral face with a small, relaxed smile.
- A plain wall behind you.
- No glasses, no hat, nothing covering the forehead.
Step 3: Make the resting face
Open Gemini (gemini.google.com) or ChatGPT, upload your photo and use this prompt. I made mine with Antigravity, Google's AI coding tool, which uses Gemini to edit images, but the prompts work the same in the Gemini app or ChatGPT.
Use the attached photo of me. Create a photorealistic portrait of only my head and the top of my neck, facing straight at the camera, with a calm, slightly smiling expression and eyes looking straight ahead. Keep my face, skin, beard and hair exactly as they are in the photo. Centre the head and make it fill about 80% of the image height. Soft, even studio light. Plain solid white background with no shadows. Square image, 1:1.
Generate a few times until you get one that really looks like you. This picture is the reference for all the others, so take your time here.
Step 4: Make the other 13 pictures
Stay in the same chat, so the tool keeps the resting face as its reference. For each picture, use this prompt and change only the last line:
Use the last image you made. Keep everything exactly the same: the same head, the same size, the same position in the frame, the same lighting and the same background. Change only this: [the change from the list below]
The changes, one per picture:
| File | The change to ask for |
|---|---|
user-face-up.png | The eyes look up. The head does not move. |
user-face-down.png | The eyes look down. The head does not move. |
user-face-left.png | The eyes look towards the left side of the image. The head does not move. |
user-face-right.png | The eyes look towards the right side of the image. The head does not move. |
user-face-upleft.png | The eyes look up and to the left side of the image. |
user-face-upright.png | The eyes look up and to the right side of the image. |
user-face-downleft.png | The eyes look down and to the left side of the image. |
user-face-downright.png | The eyes look down and to the right side of the image. |
user-face-closed.png | Both eyes gently closed, as in the middle of a blink. Relaxed face. |
user-face-wink.png | A playful wink: one eye closed, a small smile. |
user-face-shock.png | Surprised: eyebrows raised high, eyes wide open, mouth open in a small "O". |
user-face-angry.png | Annoyed: eyebrows pulled down and together, lips pressed together. |
user-face-sunglasses.png | Wearing dark aviator sunglasses, with a confident small smile. |
Tip: write "left side of the image", not "my left". "My left" is the opposite side on screen, and the AI mixes them up.
If a picture comes out with the head moved or a different light, don't try to fix it. Ask again, and repeat "the same size and the same position in the frame".
Step 5: Clean up the pictures
The script needs every file to be:
- A PNG with a transparent background. The script uses the transparent area to know where the head is, so clicks on the background don't count as pokes.
- 1024 × 1024 pixels.
- Lined up with the others. The nose sits in the same spot in every picture.
To remove the white background, use any background remover. Paint on Windows 11 and Finder on macOS (right-click → Quick Actions → Remove Background) both have one built in. ChatGPT can sometimes make a transparent background directly if you ask for one, but check the downloaded file: what looks transparent in the preview is sometimes a checkerboard painted into the picture.
To check they line up: open all 14 files in an image viewer and flick through them fast with the arrow keys. The head should stay perfectly still while only the eyes or the mouth change. If one jumps, crop or move it in any image editor until it matches, or generate it again.
Step 6: Swap them in
Copy your 14 files into the public/ folder, keeping exactly the same file names. Overwrite mine. Reload http://localhost:3000, and your face follows the mouse.
Things to test:
- Move the mouse in a circle around the face. The eyes should follow smoothly.
- Wait a few seconds. It should blink.
- Click the forehead: it gets annoyed. Click the chin: it winks. Press and drag: it looks shocked.
- Hover the Contact button. On go the sunglasses.
Not you? Make a character instead
The same 14 pictures can be anything with a face. Make the character first, then use it as the reference for the other 13 pictures, exactly as in Step 4.
An animal:
Turn the person in this image into a realistic lion character with a full mane. Keep the same head size, position and framing, the same calm expression, and the eyes and nose in the same places. Plain solid white background, soft studio light, square image.
Lions, cats, owls, foxes and dogs all work well, because their eyes face forward like ours.
A robot:
Turn the person in this image into a friendly robot head made of white plastic and brushed metal, with glowing cyan eyes. Keep the same head size, position and framing, and keep the eyes and mouth in the same places. Plain solid white background, square image.
More ideas:
- A 3D cartoon character with big expressive eyes
- A clay figure, as in stop-motion films
- A zombie version for Halloween
- A mascot for your shop or café that welcomes visitors on your website
One rule for characters: keep the eyes, nose and mouth roughly where a human face has them. The script reacts to clicks on the forehead, nose, cheeks, mouth and chin by their position, so a character whose mouth sits somewhere else will react in odd places.
Going further
The script already knows more expressions than the 14 pictures cover: a kiss, a yawn, laughing, hearts in the eyes and others. Right now they reuse the closest picture. To give one its own picture, generate it, save it in public/, and point to it in the CUSTOM_EXPRESSIONS list at the top of the script in index.html.
That is how I added a 15th picture: hover over my nose, or click it, and I stick my tongue out. I asked for the same head with only one change, "he sticks his tongue out playfully", removed the background, saved it as public/user-face-tongue.png and added one line:
tongue: '/user-face-tongue.png',
Then I told the nose to use it. In the ZONES list, hover says what each part of the face does when the mouse rests on it, and tap what it does when you click:
hover: {eyeL: 'winkl', eyeR: 'winkr', nose: 'tongue', mouth: 'kiss'},
tap: {brow: 'angry', eyeL: 'ouch', eyeR: 'ouch', nose: 'tongue', mouth: 'tongue', cheek: 'puff', chin: 'laugh'}
Show your own skills. Behind the face, a field of small square dots spells one skill at a time, and skill labels loop around the head. Both read from the SKILLS list in src/components/hero-bg/shared.ts, so put your own there.
A word on faces
Only use your own face, or the face of someone who has said yes. Your face on your own website is a nice touch. Someone else's face without asking is not.
The project is on GitHub: living-portrait, MIT licensed. If you build your own version, tag me on LinkedIn. I'd love to see the lions and robots.
