A small program that compresses JPG/JPEG images with metadata preservation with single image and bulk processing modes.
It uses Tinify to perform the processing and ExifTool to preserve the metadata.
Tinify's product TinyJPG automatically determines the best compression settings for your images with no noticeable differences at eyesight, in conjunction with ExifTool, this tool provides an easy way to compress your images and still preserve all the metadata possible.
Compared to the web version, using the API directly gives you access to upload files more than 5MB
- A Tinify API Key, that can be obtained on their Developers page
- ExifTool installed in your system and available on your $PATH as
exiftool
You need to setup your Tinify API key developer, this program allows you to set it up using either an .env
file or the apikey
flag:
A) Use of .env file: Make a copy of the .env.sample
file into a file named .env
and fill out the TINIFY_API_KEY
field with your Tinify API Key.
B) Use of -apikey flag: When running the binary, you can pass the api key directly using the -apikey
flag.
Note: If both options are provided, the
-apikey
flag will take priority over the.env
file.
./tinyphotos <options>
You can use the following command to quickly run the program without generating a binary:
go run . <options>
-apikey <string> An alternative method to the .env file, it allows the user to provide the api key directly as a flag
-file <filepath> Compresses a single file providing the relative or absolute filepath
-bulkfromfolder <folderpath> Compresses all the files in a folder providing the relative or absolute path to the folder
-maxroutines <number (default: 4)> Maximum number of images that will be processed concurrently
-log If provided, the output of the program will be saved into a file
-maxretries <number (default: 2)> Max number of retries if a request to the Tinify API fails per file
Note: Adjust the
maxroutines
option according to your network's upload speed, a higher value might generate more failure rates while making compression requests to the Tinify API. Note: Themaxretries
option only works when using thebulkfromfolder
option.
Create an executable binary for your machine using the following command:
make build
make build-all
- Support API key passthrough using
-apikey
flag - Concurrent execution for bulk processing mode
- Retry after failing with a
-maxretries
flag - Write log file (activate via CLI flag)
- Limit amount of compressions made to the Tinify API via
-complimit
flag. Useful for controlling costs - Investigate how to make the requests to the Tinify API faster for larger files
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
MIT