Download the utility from the releases and put it wherever you like to execute it.
ImageCompressor.exe [sourcePath] [targetPath] [OPTIONS]
(powershell or bash)
[sourcePath]
Path to search. Defaults to current directory[targetPath]
Path to store images. Defaults to[sourcePath]
-h, --help Prints help information
-d, --delete Delete original file after conversion
-f, --force Overwrite existing files. If false, existing files are skipped
-r, --recursive Include subdirectories
-m, --mode The compression file format to be used:
image: Jpeg, Webp
lossless: Png, WebpLl
compression: Brotli, BrotliUncompress
--parallel Number of concurrent compressions (default: 4)
-q, --quality Quality used for output
default: 98 for Jpeg, 4 for Brotli
--sample The ratio of files to process.
Use 0.025 to convert 2.5% of all images
--pattern Search pattern to discover files. Defaults to *.bmp
--minage Minimal age in days of files to process - exclude files younger than n days
--maxage Maximal age in days of files to process - exclude files older than n days
ImageCompressor can also run as service and regular trigger different task so you don't have to trigger them manually.
Since it also able to copy (recreating the relative path) and delete the original files, it basically works like a robocopy
with compression power for images!
Follow all the following steps to get ImageCompressor running as a Service.
Download the ImageCompressor.Service
from the releases and put it into your favorite location (e.g.: in C:\tools\imagecompressor
)
> New-Service -Name ImageCompressor -BinaryPathName "C:\tools\imagecompressor\ImageCompressor.Service.exe --contentRoot C:\tools\imagecompressor\I" -Description "ImageCompressor" -DisplayName "ImageCompressor" -StartupType Automatic
Put the json content into a file appsettings.json
located near to the ImageCompressor.Service.exe
.
You can even add new compression tasks to be run in certain periods
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "Console" },
{ "Name": "File", "Args": { "path": "Logs/log.txt" } }
]
},
"Settings": {
"CompressionTasks": [
{
"Name": "Compress",
"Period": "00:00:30",
"InitialDelay": "00:00:01",
"CompressionSettings": {
"SourcePath": "C:\\temp\\pictures",
"TargetPath": "C:\\temp\\pictures\\out",
"DeleteOriginal": true,
"OverwriteExisting": true,
"IncludeSubDirectories": true,
"OutMode": "Jpeg",
"MinAgeInDays": 30
}
}
]
}
}
For logging configuration refer to Serilog .
> Start-Service -Name "ImageCompressor"
- Give a star
- Raise an issue
- Start contribute