This Python script is designed to compress images to the AVIF format using the avifenc command-line tool. The script includes a basic UI using the tkinter library, allowing users to select the source folder containing their images. The compressed images are saved in an 'out' folder within the source directory.
- Python 3.x
- avifenc command-line tool (Install from libavif)
- tkinter library (
pip install tk
)
-
Install Dependencies:
-
Make sure you have Python 3.x installed.
-
Install the avifenc command-line tool from libavif.
-
Install the tkinter library by running:
pip install tk
-
-
Run the Script:
-
Execute the script by running the following command in your terminal or command prompt:
python image_to_avif.py
-
-
Select Source Folder:
- The script will open a UI dialog prompting you to select the source folder containing your images. Use the provided file dialog to choose the target folder.
-
Compression:
- The script will batch compress images in the selected folder to the AVIF format using the avifenc command-line tool.
-
Completion:
- Once the process is complete, the script will print a message indicating that the image compression is finished.
-
This script assumes that your images are in common formats like JPG, JPEG, PNG, GIF, BMP, TIFF, TIF, WebP, SVG, RAW, HEIF, HEIC, or ICO. Adjust the file extensions in the
endswith
check if needed. -
The compressed images are saved in an 'out' folder within the selected source directory.
-
In case of any errors during compression, the script will print an error message with details.
Use this script responsibly. Image compression may result in a loss of quality, and it's important to consider the trade-off between file size and image quality for your specific use case.
Feel free to customize the script or contribute improvements. If you encounter any issues or have suggestions, please open an issue or submit a pull request.