A collection of Python utilities for processing and managing image files.
- Image Cleaner (
image_cleaner.py) - Removes images smaller than a specified size - Image Converter (
image_converter.py) - Converts images to WebP format - Duplicate Finder (
move_duplicates.py) - Finds and moves duplicate images using perceptual hashing
Install the required dependencies:
pip install -r requirements.txtRemoves image files that are smaller than a specified minimum width and height.
Usage:
Command line:
# Remove images smaller than 256x256 pixels (default)
python -c "from image_utils.image_cleaner import remove_small_images; remove_small_images('C:\\Path\\To\\Images')"
# Remove images smaller than 512x512 pixels
python -c "from image_utils.image_cleaner import remove_small_images; remove_small_images('C:\\Path\\To\\Images', min_width=512, min_height=512)"Python script:
from image_utils.image_cleaner import remove_small_images
# Remove images smaller than 256x256 pixels
remove_small_images(r"e:\Google Fotos", min_width=256, min_height=256)Parameters:
path(str): Directory path to processmin_width(int): Minimum width in pixels (default: 256)min_height(int): Minimum height in pixels (default: 256)extensions(Set[str]): Image extensions to process (default: common image formats)
Supported formats: .jpg, .jpeg, .png, .bmp, .gif, .tiff, .webp
Converts images from common formats (JPG, PNG, etc.) to WebP format, which generally offers better compression. The converted images are saved in an output directory while maintaining the original folder structure.
Usage:
# Convert images in a folder and save them in 'Converted_WebP' (default quality: 80)
python image_converter.py "C:\Path\To\Your\Images"
# Specify an output folder and quality of 85
python image_converter.py "C:\Path\To\Your\Images" -o "C:\Output\WebP" -q 85
# Convert with high quality (95) to a specific output directory
python image_converter.py "C:\Path\To\Your\Images" -o "C:\Output\WebP" -q 95
# Convert and delete original files (USE WITH CAUTION!)
python image_converter.py "C:\Path\To\Your\Images" --delete-originals
# Convert with low quality for web optimization
python image_converter.py "C:\Path\To\Your\Images" -q 60Arguments:
source_dir(required): Source directory containing images to convert-o, --output: Output directory (default: creates 'Converted_WebP' folder in source directory)-q, --quality: WebP compression quality 1-100 (default: 80)--delete-originals: Delete original files after successful conversion
Supported input formats: .jpg, .jpeg, .png, .bmp, .tiff
Uses perceptual hashing (p-hash) to identify images that are visually identical or very similar, even if they have different resolutions or file formats. Found duplicates are moved to a subfolder named Duplicates.
Usage:
# Run in default folder (configured in script)
python move_duplicates.py
# Run in a specific folder
python move_duplicates.py "C:\Path\To\Your\Images"
# Example: Find duplicates in a photo library
python move_duplicates.py "e:\Photos\2024"
# Example: Process a specific directory
python move_duplicates.py "C:\Users\YourName\Pictures"How it works:
- Calculates a perceptual hash for each image
- Groups images with identical hashes
- Moves all images in duplicate groups to a
Duplicatessubfolder - Preserves original filenames, adding a counter if duplicates exist
Supported formats: .jpg, .jpeg, .png, .bmp, .gif, .tiff, .webp
- Python 3.7+
- Pillow (PIL)
- tqdm
- All tools process images recursively through subdirectories
- Original folder structures are preserved when possible
- Tools include progress bars for long-running operations
- Error handling is included for corrupted or unreadable files