| Crates.io | reduce_image_size |
| lib.rs | reduce_image_size |
| version | 0.2.4 |
| created_at | 2023-12-29 22:23:05.958652+00 |
| updated_at | 2025-09-30 21:16:12.296395+00 |
| description | Reduces size of images in a folder (and optionally sub-folders, recursively). |
| homepage | |
| repository | https://github.com/ivanbgd/reduce-image-size-rust |
| max_upload_size | |
| id | 1083733 |
| size | 90,761 |
Reduces size of images in a folder (and optionally sub-folders, recursively).
This is useful for archiving of photos, for example, as they look the same on a display even with a reduced file size.
This application reduces file sizes of images in bulk.
Supports JPEG and PNG image formats, with the following file extensions (case-insensitive): jpg, jpeg, png.
Supports Windows, macOS on Apple silicon (ARM) and x86-64, and Linux on ARM and x86-64.
Executable files for Windows, macOS and Linux can be downloaded from the Releases page of the repository.
By default, keeps the original images and creates copies with reduced file size.
By default, copies the entire folder tree, with all sub-folders that exist in the source tree.
The target folder tree will be created automatically,
and the new reduced-size images will be copied properly to their respective paths.
It is only required to provide the root target folder, and it will also be created if it doesn't exist.
Non-supported files will simply be copied to the destination.
The destination folder can be the same as the source folder, in which case the original images will be overwritten,
and not retained.
Other, non-supported files, will be retained.
If there is enough disk space, it is advised to specify a different destination folder than the source folder,
so that the original images can be retained and the newly-created reduced-size images can be inspected for quality.
A user can experiment with the resize and the quality arguments.
Also, the user can go only one level deep and not recursively, or simply experiment on a copy of an image folder.
If satisfied with the result, original images can be deleted afterwards easily to save disk and/or cloud space.
-r, --recursive--resize-q, --quality <QUALITY>-s {s,m,l,S,M,L}, --size {s,m,l,S,M,L}
See below for how to prepare the application for running.
The file paths in the examples are for Windows.
reduce_image_size D:\img_src D:\img_dstreduce_image_size D:\img_src D:\img_dst -rreduce_image_size D:\img_src D:\img_dst -r -s mreduce_image_size D:\img_src D:\img_dst --recursive --size Lreduce_image_size D:\img_src D:\img_dst -r --resize -q 60 -s lreduce_image_size D:\img_src D:\img_dst --recursive --resize --quality 60 --size Lpre-commit hooks are supported.
$ pip install pre-commit # If you don't already have pre-commit installed on your machine. Run once.
$ pre-commit autoupdate # Update hook repositories to the latest versions.
$ pre-commit install # Sets up the pre-commit git hook script for the repository. Run once.
$ pre-commit install --hook-type pre-push # Sets up the pre-push git hook script for the repository. Run once.
$ pre-commit run # For manual running; considers only modified files.
$ pre-commit run --all-files # For manual running; considers all files.
After installing it, the provided pre-commit hook(s) will run automatically on git commit.
Executable files for Windows, macOS and Linux can be downloaded from the Releases page of the repository.
Use the latest release version.
Download the appropriate archive for your OS and unpack it to a desired folder.
The archive files contain an executable.
After unpacking the archive, go to the directory with the executable and run the program as:
reduce_image_size <source_folder> <destination_folder> [options]
Or, provide full path to the program.
Paths to the source and destination folders can be absolute or relative.
This section applies in case you don't have an executable and need to build it.
It may depend on the OS. Namely, while installation of nasm is needed on Windows, it is not needed on macOS.
nasm doesn't support Apple silicon, but this crate works on macOS Sonoma 14.5 on Apple M2 Pro processor.
Linux hasn't been tested. Also, macOS on x86 architecture hasn't been tested.
The library and the application require:
Add CMake to the PATH environment variable.
Make sure to build the application in release mode as it will run much faster that way.
Build:
cargo build --release
Run:
cargo run --release -- <source_folder> <destination_folder> [options]
This Rust crate was originally meant as a binary (executable) crate, i.e., an application, but it was later decided to publish the library part, so it can be used as a Rust library, too.
Only the main image-processing function, process_images, has been made public.
Helper functions have been made private.