简体中文 | English
LiYing is an automated photo processing program designed for automating general post-processing workflows in photo studios.
LiYing can automatically identify human bodies and faces, correct angles, change background colors, crop passport photos to any size, and automatically arrange them.
LiYing can run completely offline. All image processing operations are performed locally.
![]() |
![]() |
![]() |
---|---|---|
![]() |
![]() |
![]() |
Note: This project is specifically for processing passport photos and may not work perfectly on any arbitrary image. The input images should be standard single-person portrait photos.
It is normal for unexpected results to occur if you use complex images to create passport photos.
If you are a Windows user and do not need to review the code, you can download the bundled package (tested on Windows 7 SP1 & Windows 10).
The bundled package does not include any models. You can refer to the Downloading the Required Models section for instructions on downloading the models and placing them in the correct directory.
If you encounter issues while running the program, please first check the Prerequisites section to ensure your environment is properly set up. If everything is fine, you can ignore this step.
Run the BAT script:
cd LiYing
run.bat ./images/test1.jpg
Run the WebUI interface:
# Run WebUI
cd LiYing
run_webui.bat
# Open your browser and visit 127.0.0.1:7860
You can install and configure LiYing locally by following the instructions below.
LiYing depends on AGPicCompress, which in turn requires mozjpeg
and pngquant
.
You may need to manually install pngquant
. Refer to the official pngquant documentation and add it to the appropriate location.
LiYing checks for pngquant
in the following locations, which you can configure:
- Environment variables (recommended)
- LiYing/src directory
ext
directory under LiYing/src
This allows AGPicCompress to locate and use pngquant
for PNG image compression.
You need to install the latest Microsoft Visual C++ Redistributable.
If you are using Windows, your minimum version should be Windows 7 SP1 or higher.
You can obtain the LiYing project code by running:
git clone https://github.com/aoguai/LiYing
cd LiYing ## Enter the LiYing directory
pip install -r requirements.txt # Install Python helpers' dependencies
Note: If you are using Windows 7, ensure you have at least Windows 7 SP1 and onnxruntime==1.14.0, orjson==3.10.7, gradio==4.44.1
.
Download the models used by the project and place them in LiYing/src/model
, or specify the model paths in the command line.
Purpose | Model Name | Download Link | Source |
---|---|---|---|
Face Recognition | Yunnet | Download Link | Yunnet |
Subject Recognition and Background Replacement | RMBG-1.4 | Download Link | RMBG-1.4 |
Body Recognition | yolov8n-pose | Download Link | ultralytics |
Note: For the yolov8n-pose model, you need to export it to an ONNX model. Refer to the official documentation for instructions.
We also provide pre-converted ONNX models that you can download and use directly:
Download Method | Link |
---|---|
Google Drive | Download Link |
Baidu Netdisk | Download Link (Extraction Code: ahr9) |
GitHub Releases | Download Link |
# View CIL help
cd LiYing/src
python main.py --help
For Windows users, the project provides a batch script for convenience:
# Run BAT script
cd LiYing
run.bat ./images/test1.jpg
# Run WebUI
cd LiYing/src/webui
python app.py
python main.py --help
Usage: main.py [OPTIONS] IMG_PATH
Options:
-y, --yolov8-model-path PATH Path to YOLOv8 model
-u, --yunet-model-path PATH Path to YuNet model
-r, --rmbg-model-path PATH Path to RMBG model
-sz, --size-config PATH Path to size configuration file
-cl, --color-config PATH Path to color configuration file
-b, --rgb-list RGB_LIST RGB channel values list (comma-separated)
for image composition
-s, --save-path PATH Path to save the output image
-p, --photo-type TEXT Photo types
-ps, --photo-sheet-size TEXT Size of the photo sheet
-c, --compress / --no-compress Whether to compress the image
-sv, --save-corrected / --no-save-corrected
Whether to save the corrected image
-bg, --change-background / --no-change-background
Whether to change the background
-sb, --save-background / --no-save-background
Whether to save the image with changed
background
-lo, --layout-only Only layout the photo without changing
background
-sr, --sheet-rows INTEGER Number of rows in the photo sheet
-sc, --sheet-cols INTEGER Number of columns in the photo sheet
-rt, --rotate / --no-rotate Whether to rotate the photo by 90 degrees
-rs, --resize / --no-resize Whether to resize the image
-sz, --save-resized / --no-save-resized
Whether to save the resized image
-al, --add-crop-lines / --no-add-crop-lines
Add crop lines to the photo sheet
--help Show this message and exit.
In this version, the data
directory contains standard ID photo configuration files (size_XX.csv
) and commonly used color configurations (color_XX.csv
). You can modify, add, or remove configurations based on the provided CSV template format.
Note: This version includes changes to CIL parameters. Please carefully read the latest CIL help documentation to avoid issues.
- 2025/02/07 Update
- Added WebUI
- Optimized configuration method by replacing INI files with CSV
- Added CI/CD for automated builds and testing
- Added options for layout-only photos and whether to add crop lines on the photo grid
- Improved fallback handling for non-face images
- Fixed known bugs
- Added and refined more photo sizes
Previous Changelog
- 2024/08/06 Update
- Added support for entering width and height in pixels directly for
photo-type
andphoto-sheet-size
, and support for configuration viadata.ini
. - Fixed issues related to some i18n configurations; now compatible with both English and Chinese settings.
- Fixed other known bugs.
- Added support for entering width and height in pixels directly for
The project was created to help my parents complete their work more easily. I would like to thank my parents for their support.
Special thanks to the following projects and contributors for providing models and theories:
You might also be interested in the image compression part, which is another open-source project of mine:
It depends on:
LiYing is an open-source project, and community participation is highly welcomed. To contribute to this project, please follow the Contribution Guide.
LiYing is open-sourced under the AGPL-3.0 license. For details, please refer to the LICENSE file.