Crates.io | snapcrop |
lib.rs | snapcrop |
version | 0.1.1 |
source | src |
created_at | 2023-10-09 20:36:06.103208 |
updated_at | 2023-10-09 22:06:38.608365 |
description | CLI for crop/resize of large amounts of images with configurable resolutions |
homepage | |
repository | |
max_upload_size | |
id | 998446 |
size | 3,897,168 |
Simple CLI utility for cropping large amounts images to a specified set of resolutions or aspect ratios.
Useful for dataset preperation for machine learning tasks.
Images will be matched to the nearest aspect ratio from your specified target resolutions, ensuring no distortion. The tool prioritizes the image's original aspect ratio during resizing and centers the content during cropping. Additionally, snapcrop avoids upscaling smaller images, preserving their original quality.
snapcrop uses the hash of the origninal input image to avoid reprocessing images, allowing incremental re-runs into the same output directiory (does not respect changes to the --res parameter, to avoid having to open the image and run resize logic to determine if we can skip).
Crate
cargo install snapcrop
Github
git clone https://github.com/functorism/snapcrop.git
cd snapcrop
cargo build --release
Crop all your images with snapping
Examples:
Crop images to SDXL training resolutions
snapcrop out --res 1024x1024,1152x896,896x1152,1216x832,832x1216,1344x768,768x1344,1536x640,640x1536
Crop images to the closest resolution of the provided 1:1 sizes
snapcrop out --res 1024,768,512
Crop images to the closest resolution of 1:1 aspect ratio between 512x512 and 1024x1024 with a step of 64
snapcrop out --res 512:1024:64
Crop images with a fixed width of 512 and a height between 1024 and 512 with a step of 64
snapcrop out --res 512:1024:64x512
Crop images to resolution in either orientation (512x768 and 768x512)
snapcrop out --res [512x768]
Combine freely
snapcrop out --res [512x768],1024,512:768:64x768:1024:32
Usage: snapcrop [OPTIONS] --res <RESOLUTIONS> <OUTPUT_PATH>
Arguments:
<OUTPUT_PATH>
Output dir path for images
Options:
--res <RESOLUTIONS>
List of resolutions
-i, --input-file <IMAGE_LIST_PATH>
File list path, stdin used otherwise
-l, --log <LOG_PATH>
Output debug info to log
-v, --verbose
Output debug info to stderr
-f, --format <IMAGE_FORMAT>
[default: png]
-h, --help
Print help (see a summary with '-h')
snapcrop squares --res 256
snapcrop landscape --res 256x128
snapcrop portrait --res 128x256
snapcrop mixed --res 256,[128x256]
snapcrop steps --res [128:256:8x128:256:8]
The main libraries this CLI uses are: