A simple and efficient Node.js script to convert images (PNG, JPG, JPEG, and
WEBP) into the AVIF format with optimized compression and high-quality output.
This project utilizes the sharp
library for image processing.
- Supports PNG, JPG, JPEG, and WEBP formats.
- Converts images to AVIF format with adjustable quality.
- Processes multiple images in parallel for faster conversions.
- Automatically creates the output directory if it doesn’t exist.
- Logs detailed conversion progress and errors.
└── 📁image-to-avif
└── 📁src
└── 📁images
└── //your images
└── 📁output
└── //result images
└── index.js
└── .gitignore
└── package-lock.json
└── package.json
└── README.md
- Clone the repository or download the source code.
- Navigate to the project directory:
cd image-to-avif
- Install the dependencies:
npm install
- Add images to the
src/images
directory. - Run the script:
npm start
- The converted AVIF images will be saved in the
src/output
directory.
- Quality Setting: The AVIF quality can be adjusted in
src/index.js
by modifying thequality
variable:const quality = 50; // Adjust quality (0-100)
- Parallel Processing: The script uses the number of available CPU cores for
optimal performance. You can override this by changing the
maxThreads
variable:const maxThreads = 4; // Example: limit to 4 threads
Input:
src/images/
├── default.png
Output:
src/output/
├── default.avif
This project is licensed under the MIT License. Feel free to use and modify it as needed.
Contributions are welcome! Feel free to submit a pull request or open an issue to report bugs or suggest improvements.