Skip to content

resize

Resize and crop images to a target resolution.

Usage

bash
datasety resize --input ./images --output ./resized --resolution 768x1024

Options

OptionDescriptionDefault
--input, -iInput directory(required*)
--output, -oOutput directory(required*)
--input-imageSingle input image
--output-imageSingle output image
--resolution, -rTarget resolution (WIDTHxHEIGHT)
--megapixelTarget megapixel count (e.g., 0.5, 1.0)
--aspect-ratioAspect ratio W:H (e.g., 1:1, 16:9, 3:2)
--crop-positiontop, center, bottom, left, rightcenter
--input-formatComma-separated formatsjpg,jpeg,png,webp
--output-formatjpg, png, webpjpg
--output-name-numbersRename to 1.jpg, 2.jpg, ...false
--upscaleUpscale images smaller than targetfalse
--min-resolutionSkip images below this size (e.g., 256x256)
--workersParallel workers for processing1
--recursive, -RSearch input directory recursivelyfalse
--progressShow tqdm progress barfalse
--dry-runPreview without writing filesfalse

Examples

bash
# Batch resize with top crop
datasety resize -i ./raw -o ./dataset -r 1024x1024 --crop-position top

# Single image
datasety resize --input-image photo.jpg --output-image resized.jpg -r 512x512

# Sequential numbering
datasety resize -i ./photos -o ./processed -r 768x1024 --output-name-numbers
bash
# Megapixel mode: preserves each image's native aspect ratio
datasety resize -i ./raw -o ./dataset --megapixel 1.0

# Megapixel mode: force specific aspect ratio
datasety resize -i ./raw -o ./dataset --megapixel 0.5 --aspect-ratio 1:1

# Megapixel mode: 1.0 MP at 16:9
datasety resize -i ./raw -o ./dataset --megapixel 1.0 --aspect-ratio 16:9

How It Works

  1. Finds all images matching input formats
  2. Skips images smaller than target resolution
  3. Resizes proportionally so the smaller side matches target
  4. Crops from the specified position to exact dimensions
  5. Saves with high quality (95% for jpg/webp)

Released under the MIT License.