日常写真から公的証明写真を自作するAIエージェントスキルを作った:スーツ着せ替えとコンビニ印刷まで一発完結 #Python - Qiita
@lumichy

Created an AI agent skill to make official ID photos from everyday photos: complete the process from changing into a suit to convenience store printing in one go

  • AI
  • Python
  • Image generation
  • Agent
  • LLM
0
Posted at 2026-11-12

カバー画像

Job application resumes, passport renewals, driver's licenses, My Number cards——.

Have you ever had to search for photo booths (boxes) or photo studios every time you needed an ID photo due to procedures every few years or urgent situations?

Even if you think, "My smartphone camera is nice, I'll take a self-shot photo at home and save some money," when you try to do it yourself, you might face issues like shadows from the walls, dark skin tones from room lighting, slightly tilted gaze or head, or not even wearing a suit... Additionally, you might have spent hours manually trimming to precise millimeter specifications like "3mm head space" or "34mm face length," and arranging the face for L-size photo paper (4-part layout) using tools like Photoshop or Word, only to end up with a half-day wasted.

Therefore, by simply asking your regularly used AI agent, "Please create passport and resume ID photos from this photo,"I have open-sourced an Agent Skill that seamlessly performs all steps from naturally changing into a suit, correcting posture, trimming to official millimeter standards, to creating a printable sheet for convenience store 300DPI printing.

[!NOTE]
📁 GitHub repository

https://github.com/lumichy/skills/tree/main/skills/id-photo-studio

※Includes a complete collection of prompts, millimeter-precision trimming & layout scripts, and sample images.

In this article, we will detail the design philosophy of this skill, the actual conversion steps using outdoor snapshots, prompts, usage in agents, and the technical considerations and precautions for why we chose hybrid processing instead of using a single image generation AI.

Quick Reference for Basic Information

Item Content
Skill Name id-photo-studio (ID Photo Studio / ID Photo Studio)
Source code github.com/lumichy/skills/tree/main/skills/id-photo-studio
License MIT License
Supported standards Passport (40×30mm), My Number Card・Passport (45×35mm), Driver's License (30×24mm), U.S. Visa (51×51mm), TOEIC (40×30mm), Custom size
Output format Digital submission single JPEG + Convenience store printing face sheet (L size 89×127mm / 2L size 127×178mm, 300 DPI, with 50mm ruler scale for proofing)
Core technologies AI image generation and editing + Python precise image processing (tilt horizontal correction, frequency separation face lock synthesis, standard trimming)
Required libraries pillow, numpy, scipy

1. Actual conversion process: converting an outdoor 2-shot snap into an ID photo

As the saying goes, "a picture is worth a thousand words," so let's look at the process of converting an input photo into an ID photo, along with the actual prompts, based on the sample included in the repository.

Original photo: outdoor 2-shot snap (with two people)

The original image is a casual outdoor snap photo of two people standing side by side, with their heads slightly tilted to the left and right.

元写真:屋外スナップ写真
Original photo: head tilt, casual civilian clothes, outdoor natural light and tree background, 2 people side-by-side snap photo

From here, the agent will autonomously proceed through the steps of geometric correction, AI editing, frequency separation synthesis, and millimeter standard trimming.

Brother: Head tilted +17.93 degrees to the right shoulder up, corrected to horizontal
  • Sister: Head tilted -25.02 degrees to the left shoulder down, corrected to horizontal
  • This results in a standard 3:4 portrait where the line connecting both eyes is perfectly horizontal.

    Step 2: AI Suit Change and Studio Lighting (Actual Prompt)

    Input the horizontally corrected portrait image into the image generation/editing AI to instruct it to create a studio-style official ID photo (証明写真) and save it to <OUTPUT_PATH>.

    This skill prepares three prompt patterns according to the intended use.

    Prompt for Pattern A (Suit Change + Closed-Mouth Official Photo Expression)

    For purposes where a "serious expression without showing teeth" is essential, such as official documents like passports, My Number cards, or job application resumes.

    Edit the reference photo at <INPUT_IMAGE_PATH> to create a professional Japanese official ID photo (証明写真) and save it to <OUTPUT_PATH>.

    Prompt for Pattern B (Maintain Original Clothing + Studio Photo Background, Lighting, and Posture)

    Prompt for when you want to use the student ID, favorite casual clothes, or uniform as is.

    Edit the reference photo at <INPUT_IMAGE_PATH> to create an official ID photo (proof photo) and save it to <OUTPUT_PATH>. Strict Requirements: 1. Identity & Clothing Preservation: Keep the exact same person's facial features, expression, and current clothing. Tidy up minor wrinkles if needed. 2. Posture & Alignment: Center the head and level the shoulders so the subject faces straight forward toward the camera. 3. Lighting & Background: Remove uneven lighting or shadows on the face, and replace the background with a completely flat, solid, shadow-free light blue background. 4. Framing: Include enough headroom above the hair and chest area below the chin for subsequent exact millimeter cropping.

    Prompt for Pattern C (100% preservation of the original facial features and expression + suit replacement and background change)

    Prompt for when you want to create an ID photo (proof photo) such as a staff ID or profile photo, maintaining the original natural smile and teeth alignment without any distortion, even by 1 millimeter, while changing the suit.

    Edit the reference photo at <INPUT_IMAGE_PATH> to create an ID photo (proof photo) and save it to <OUTPUT_PATH>. Strict Requirements: 1. Strict Face & Expression Lock (DO NOT MODIFY THE FACE): Keep the person's head, facial features, eyes, gaze, mouth, and exact facial expression 100% untouched and identical to the input photo. Do NOT alter, retouch, or regenerate their expression or facial structure in any way. 2. Lighting & Shadow Removal: Remove any uneven shadows or harsh lighting casts on the face and neck so the illumination looks clean and balanced, without changing the facial pixels or expression. 3. Attire Replacement Only: Replace only the clothing below the neck with a neat dark business suit and crisp white shirt, naturally aligned with the neck. 4. Background Replacement: Replace the background with a completely flat, solid, uniform, shadow-free light blue background. 5. Framing: Frame as a centered head-and-shoulders bust portrait with ample headroom above the head.

    Step 3: Frequency Separation Lock Composite of the Subject's Facial Parts (Python)

    When outputting solely with AI, the eyes, nose, and mouth, as well as dental alignment, are inevitably slightly redrawn.

    Therefore, using the script (composite_original_head.py), the inner facial parts (eyebrows, eyes, nose, mouth, and moles) are extracted with high-frequency component lock plus Gaussian low-pass color correction from the original photo, and seamlessly blended into the AI-generated suit and neckline images.

    • Case C:: The entire face (eyes, nose, mouth, smile, and dental alignment) is completely locked from the original photo
    • Case A:: The mouth area adopts the AI's closed-mouth expression while the eye area to eyebrow region is completely locked with original pixels

    Step 4: Millimeter-Specification Trimming & Convenience Store Printing Sheet Generation

    Finally, the script (process_id_photo.py) performs millimeter-level pixel calculations according to public standards, outputting individual photos and convenience store printing sheets.

    Considering smartphone viewing, we will introduce the details of each completed sample in a vertical scroll format.

    ① Brother: Pattern A (Closed-Mouth Expression of ID Photo + Suit)

    The eyes are kept at 100% original pixels, the mouth area is corrected to a natural closed-mouth state, and it is an official ID photo with a suit worn.

    お兄ちゃん パターンA
    Passport/My Number Card Specification (45×35mm)/ Tilt Level Correction (+17.93°) + 100% Original Eye Area Lock + Closed-Mouth Correction

    ② Brother: Pattern C (100% Maintenance of Original Smile, Eyes, and Dental Alignment + Suit)

    This is a portrait that maintains the original smile, gaze, and dental alignment without any changes, achieving a suit change and studio lighting with a blue background.

    お兄ちゃん パターンC
    Passport/My Number Card Specification (45×35mm)/ Tilt Level Correction (+17.93°) + 100% Maintenance of Face, Smile, and Dental Alignment

    ③ Brother: Convenience Store Printing L-Size Sheet

    An L-size sheet for 4-side mounting that can be printed immediately at multi-copy machines such as Seven-Eleven and Lawson.

    お兄ちゃん L判シート
    L-size (89×127mm) 300 DPI / Cutter guide (cut line) with 50mm ruler scale for actual size confirmation

    ④ Sister: Pattern A (closed-mouth proof photo expression + formal)

    - Correcting the head tilted at -25.02 degrees to horizontal, while preserving the original facial features, to create a calm formal proof photo.

    妹さん パターンA
    Passport/My Number specification (45×35mm) / Tilt horizontal correction (-25.02°) + 100% face lock for the eyes + closed-mouth correction

    ⑤ Sister: Pattern C (100% maintenance of original smile + formal)

    The sister's original cute smile expression is completely preserved, converting it into a formal wear and proof photo background.

    妹さん パターンC
    Passport/My Number specification (45×35mm) / Tilt horizontal correction (-25.02°) + 100% maintenance of face, smile, and teeth alignment

    ⑥ Sister: Convenience store printing L-size print sheet

    It's a 4-sided proof photo sheet for the sister. A 50mm ruler scale is attached at the bottom for checking actual size after printing.

    2. Why is it not possible with "AI-generated alone" or "Python alone"?

    Actually, before developing this skill, I failed with two approaches.

    First, I thought, "If I ask an image generation AI to create a proof photo with the person's face wearing a suit, it should work instantly." However, even with the latest image generation models, during the AI's image encoding and decoding process,the eye size, double eyelid width, teeth alignment, nasal bridge shape, and mole positions subtly change, resulting in a different person. In public proof photos, if the face is different from the original, it's immediately rejected.

    Next, I tried, "What if I use Python's OpenCV or Pillow to cut out the face into an ellipse and composite it with a free suit素材?" However, the human face and neck area have complex shadows. When pasting, the neck and collar boundary becomes prominent, leaving a strong sense of dissonance, like a collage image.

    Therefore, I adoptedthe hybrid design that divides the strengths of AI image generation and Python's precise image processing.

    [ Input photo (tilt, casual clothes, cluttered background) ] │ ▼ 【Step 1: Tilt geometric correction (Python)】 Calculate the angle θ from the coordinates of both pupils → horizontal rotation & standard portrait cropping │ ▼ 【Step 2: Harmony of clothing, neck, and background (image editing AI)】 Suit replacement · background removal · blending of collar and lapel shadows are handled by AI │ ▼ [Step 3: Full Restoration of Authenticity (Python Frequency Blend)] Blend the inner part of the face (eyes, nose, mouth, and mole) seamlessly using high-frequency component locking from the original photo │ ▼ [Step 4: Precise Public Official Millimeter Specifications & L-size Alignment (Python)] Pixel calculation of head margin and face ratio + output of sheet with stamp and 50mm ruler scale

    Summary of How to Choose Among the 3 Correction Patterns

    • Pattern A (Suit Replacement + Closed-mouth Proof Photo Expression):
      Ideal for situations where official standards require "no smile" and "suit wearing", such as passports, My Number cards, and job hunting.
    • Pattern B (Keep the Original Clothing + Background, Lighting, and Posture Correction):
      Ideal for situations where you want to use your original student ID, qualification certificate, or favorite casual clothes or office casual.
    • Pattern C (Maintain 100% Original Smile and Expression + Suit Replacement):
      Ideal for situations where you want to combine your natural smile and suit appearance, such as employee ID cards, business SNS profile icons, and speaker profiles.

    3. How to Use the Skill and Recommended Execution Environment

    This skill can be used simply by placing it in the AI agent's skill directory.

    Recommended Agent Environment: Codex or Antigravity is Best

    For the agent environment to run this skill, we strongly recommend using Codex or Google Antigravity, which are proficient in both text reasoning and advanced image generation and multimodal processing.

    These environments come with high-performance image generation and visual tools built-in, so the most natural suit replacement and collar harmony can be achieved without any additional settings.

    Notes When Using with Claude Code: We Recommend Connecting to the Free "AGNES"

    On the other hand, if you use Claude Code, a CLI-type coding agent that is very popular, the standard environment does not include an image generation tool.

    Therefore, if you are using Claude Code, you need to prepare an external tool or skill that can perform image generation in advance.

    If you don't have a paid image generation API or environment, we recommend using the fully free multimodal AI tool "AGNES" locally. By integrating the following skill into Claude Code, you can immediately build a free and high-precision image editing and generation pipeline.

    • AGNES Skill (GitHub): skills/agnes-local-generation on GitHub
    • Detailed explanation article: AGNES-2: A Guide to Creating a Multi-modal AI Image Generation Tool that is Completely Free and Runs Locally

    Example instructions for the agent

    In the agent's chat window, you can talk naturally in natural language by specifying the path of the original photo and who's proof photo you want to create. Even if the photo includes multiple people, the agent will extract and process the target individual if you specify them.

    Please create a passport-sized proof photo for the brother on the left side of this two-shot photo (./samples/original_two_shot.jpg). Since I want to print it on a convenience store L-size photo paper, I also need the print sheet. Please use a dark suit, light blue background, and pattern A with closed mouth.

    If you want to create a proof photo for the sister on the right side, you can give instructions by changing the target as follows.

    Please create a proof photo for the sister on the right side of this photo. The purpose is for the My Number Card (45×35mm), with an L-size print sheet included, and pattern A with formal wear, with a light blue background.

    Once the agent receives the instructions, it will autonomously proceed through the following steps.

    1. Requirement confirmation and target identification: Confirm the target person (older brother/sister, etc.), the purpose (passport/resume, etc.), the print paper (L-size/2L-size/only individual data), background color, and correction pattern (A / B / C).
    2. Tilt and horizontal correction: Measure the coordinates of the target person's eyes using --draw-grid, and then use --level-and-crop to correct the head tilt with horizontal rotation, extracting a single portrait.
    3. AI studio processing: Call the image generation tool within the environment, generating studio lighting and a base image of the suit.
    4. Identity blending: Restore and composite the eyes and facial parts of the original photo using composite_original_head.py.
    5. Millimeter specification trimming & sheet generation: Accurately cut out to passport size (45×35mm) using process_id_photo.py, and output an L-size sheet with a border and a 50mm scale for actual size confirmation.

    Printing procedure at convenience stores (extremely important)

    Save the generated *_sheet_L.jpg to your smartphone, and print it at a multi-copy machine (photo printer) at places such as Seven-Eleven, Lawson, FamilyMart, etc.

    There is one important note here. When printing, always select ``Border included printing'' (to fit the entire paper).

    If you select ``borderless (full page printing)'', the machine will automatically enlarge it by several percent, which will cause the ratio of the face, calculated precisely in millimeters, to become distorted. If you place a ruler against the printed ``50mm actual size confirmation scale'' at the bottom of the sheet and it measures exactly 50mm, it proves that the sheet is the correct size.

    4. Notes and limitations when using

    This is a very useful skill, but there are two important points to keep in mind when actually using it.

    Note 1: The agent must have an "image generation and editing tool"

    Since this skill is a hybrid setup, the agent environment needs to have not only a Python environment but also "tools or skills that can load and edit or generate images".

    • Use an environment that has built-in image generation capabilities, such as Codex or Antigravity, or connect with tools like Claude Code, etc., as mentioned earlier.
    • If the environment does not have any image editing tools, AI-based outfit changes or corrections to the neck area cannot be performed. In such cases, the agent will operate in a mode that only performs "background color replacement via Python scripts (--replace-bg) and 100% specification trimming and face alignment, keeping the original casual clothes".

    Note 2: If the reasoning ability or generation model is weak, it may look unnatural (especially in Pattern C)

    The most important point to be cautious about is the reasoning ability of the agent and the quality of the image generation model used.

    In particular, for "Pattern C (mode that maintains 100% of the original photo's face and expression)", it is necessary to let the AI seamlessly blend the original head's neck area, contours, suit collar, and background lighting in Stage 1.

    Using a low-reasoning small LLM or a weak image generation model that doesn't follow instructions well can easily lead to the following failures:

    • The angle between the neck and the suit collar is mismatched, making the neck look unnaturally long.
    • The AI redraws the contours of the original face, resulting in unnatural steps or double chins at the boundaries.
    • Boundary noise remains between the background color and the suit's outline.

    If you find the generated results unnatural, please switch to a more advanced model (frontier model) or adjust the original head extraction range wider and re-instruct the agent.

    5. Summary

    The strength of AI agents lies in their ability to automatically complete complex tasks that cannot be achieved by a single tool such as "generating images with prompts" or "executing scripts" by combining them appropriately.

    • Role of AI: Outfit change, natural harmony of the neck and background, reproduction of studio lighting
    • Role of Python: Eye-level correction via angle calculation, 100% locking of the person's features using frequency separation, specification trimming in millimeters, and face alignment for 300DPI printing

    Before you suddenly need a passport photo and end up paying hundreds of yen to take one or struggling with Photoshop, please definitely try this skill by integrating it into your local AI agent.

    [!TIP]
    📁 Related Links Collection

    What do you usually do when you need a passport photo? If you have any ideas like 'I also want this specification size or feature,' please let me know in the comments section!

    0
    1
    comment0

    Register as a new user and use Qiita more conveniently

  • You get articles that match your needs
  • You can efficiently read back useful informationYou can use dark themeWhat you can do with signing up
    Sign upLogin