This project provides a command-line tool to bulk trim images based on their alpha channels, using C++ libraries such as stb_image
, stb_image_write
, spdlog
, and CLI11
. It resizes images by trimming transparent pixels and applies the largest bounding box found among a group of images.
- Load images in
.png
,.jpg
, and.jpeg
formats. - Automatically find the smallest rectangle that contains non-transparent pixels (bounding box) for each image.
- Normalize all images to the largest found bounding box.
- Save the modified images back to disk.
- Extensive logging with
spdlog
.
The project uses the following libraries:
- CLI11 for command-line argument parsing.
- stb_image for loading image files.
- stb_image_write for writing modified images.
- spdlog for logging.
Ensure these libraries are included and correctly configured in your build environment.
- C++23 or later.
- CMake for build configuration.
- Ninja or any other build system compatible with CMake.
- The required libraries mentioned above.
-
Clone the repository:
git clone https://github.com/AnonimiAngels/image_trimmer.git cd image_trimmer
-
Use the project manager script to generate build files, build the project, and more:
project_manager.py --clear --generate --build --type Release
-
Run the tool:
./bin/image_trimmer -p /path/to/image_directory
- When the build is successful, the executable will be located in the
bin
directory.
To run the tool, provide a path to a directory containing images:
./image_trimmer -p /path/to/image_directory
- The tool will look for .png, .jpg, and .jpeg files in the specified directory and its subdirectories.
- It will then trim the images by removing transparent pixels and normalize them to the largest bounding box found among the images.
The tool supports the following command-line options:
-p, --path
: Path to the directory containing images.
./image_trimmer -p ./images
This command will process all images in the images
directory and
its subdirectories
.
- The tool uses spdlog for logging.
- Log messages include:
- Number of images found.
- The biggest bounding box dimensions.
- Any errors encountered during image loading or processing.
The project is licensed under the MIT License. See the LICENSE file for more information.