Find and modify images in a directory, similar to findutils
Project description
imgfind
A simple Python utility to find and modify images in a filesystem, somewhat similar to findutils.
Also included are lightweight wrappers for ffprobe and GraphicsMagick via vfind and teeny utilities, for finding video files and quickly recompressing/optimizing images, respectively.
Installation
Requires Python 3.5 or higher, but you should really be using the latest stable release.
python3 -m pip install -U imgfind
Usage
The main utility installs as ifind globally, can be invoked with python3 -m imgfind.find if not on PATH.
Use --help to see all available options. Some examples:
# list all 3840x2160 images in the current directory
ifind -w 3840 -h 2160
# list all 16:9 aspect ratio images in the current directory
ifind --ratio 16:9
# generate 200px-max thumbnail images from all images in ./src, storing them in ./thumbnails
ifind ./src --convert jpg --resize-max 200 --dest ./thumbnails
# find all PNG images in the user's Pictures directory that are at least 1920 pixels wide, and convert them to WebP using ImageMagick (via --exec)
ifind ~/Pictures --width '>=1920' --format png --exec 'magick convert -format webp {}'
# Convert large landscape images to 1080p wallpapers
ifind ./wallpapers --width '>=1920' --ratio landscape \
--exec 'gm mogrify -format jpg -quality 85 -resize 1920x1080^ -gravity Center -crop 1920x1080 {}'
Finding video files
If ffmpeg is installed, the vfind utility can be used similarly to ifind to find video files.
Use --help to see all available options. Some examples:
# list all 2160p videos in the current directory
vfind --res 2160
# list all 16:9 aspect ratio videos in the current directory
vfind --ratio 16:9
# Advanced filtering can be done via Python expressions
# Find portrait videos with either H.265/HEVC or AV1 codecs, and 50 fps or higher
vfind --ratio portrait --filter 'fps >= 50 and re.search(r"265|hevc|av1", video_codec)'
# use without package in path
python3 -m imgfind.vfind
Optimizing image files
The teeny utility can be used to optimize or recompress images. This utility is not lossless by default and will, by design, result in loss of quality for processed images.
The most simple behavior is to pass a single image file, which will replace it with a more optimized/heavily compressed version if needed. Use --help to see all available options.
# optimize a single image
teeny example.jpg
# optimize a directory recursively
# recursive operations run conversion subprocesses in parallel for improved performance
teeny -r ~/Pictures/Wallpapers
# convert all PNG images to WebP at 70% quality, resizing to a maximum height of 1080px
teeny -r --glob '*.png' -f webp --quality 70 --height 1080 .
# pipe file paths from find to teeny using "-" for stdin
find ~/Pictures -name '*.png' | teeny -f webp -
# use without package in path
python3 -m imgfind.teeny
Optimizing video files
If ffmpeg is installed, the vteeny utility can be used similarly to teeny to optimize video files. It encodes to HEVC by default and uses hardware encoding when available.
Quality settings are hand-picked per codec with a focus on smaller sizes. If you want manual control over quality you should use ffmpeg directly instead of vteeny.
Use --help to see all available options. Some examples:
# optimize a single file
vteeny example.avi
# convert all videos to AV1/WebM, resizing to a maximum resolution of 1080p
vteeny -v av1 -v webm --res 1080 -r .
# pipe file paths from vfind to vteeny using "-" for stdin
vfind --res 2160 | vteeny --res 1080 -
# use without package in path
python3 -m imgfind.vteeny
Building
You can run the imgfind code directly if you have the dependencies (Pillow/piexif) installed. No building is required as long as Pillow has been built. The imgfind package will handle updating paths at runtime if needed should you import or execute it outside of your site-packages.
If you want to build a release and optionally install locally or upload it to PyPI:
# Generate completion files (optional)
python3 scripts/completion_bash.py
python3 scripts/completion_fish.py
python3 scripts/completion_zsh.py
# Build package
python3 -m pip install -U build twine
python3 -m build --wheel
# Upload build to PyPI
python3 -m twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file imgfind-0.3.9-py3-none-any.whl.
File metadata
- Download URL: imgfind-0.3.9-py3-none-any.whl
- Upload date:
- Size: 34.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cf575925f166419b2f0d0d154d6bad0f4e09f73dc4774c14fada0f29fc55f5f
|
|
| MD5 |
0150e89b34358e4f6373f16115ef0ab7
|
|
| BLAKE2b-256 |
840c8330936e1edecbf39bd9087c77a5ad83cf2ca94dfc025b8a4b65f440d47e
|
Provenance
The following attestation bundles were made for imgfind-0.3.9-py3-none-any.whl:
Publisher:
python-publish.yml on Alanaktion/imgfind
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
imgfind-0.3.9-py3-none-any.whl -
Subject digest:
7cf575925f166419b2f0d0d154d6bad0f4e09f73dc4774c14fada0f29fc55f5f - Sigstore transparency entry: 2153214424
- Sigstore integration time:
-
Permalink:
Alanaktion/imgfind@a4ebd75b77ae2b9516a46266c4289e8dede1e0f7 -
Branch / Tag:
refs/tags/v0.3.9 - Owner: https://github.com/Alanaktion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a4ebd75b77ae2b9516a46266c4289e8dede1e0f7 -
Trigger Event:
push
-
Statement type: