C++23 library and command-line toolset for converting images to the modern AVIF format.
Table of Contents
A high-performance C++23 library and command-line toolset for converting images to the modern AVIF format.
This project leverages stb_image for broad input format support, stb_image_resize2 for high-quality scaling, libavif for AVIF encoding, and Exiv2 for preserving metadata (EXIF, IPTC, XMP).
- C++23 Library (
img2avif_lib): A reusable library providing a cleanstd::expectedinterface for AVIF conversion and resizing. img2avifCLI: A fast 1:1 image to AVIF converter.img2avifsCLI: A batch resizer that outputs multiple responsive target sizes (480, 680, 800, 1024, 1280) from a single input image.- Adjustable Quality & Speed: Exposes AVIF encoding parameters.
- Metadata Preservation: Optionally keeps EXIF and XMP data intact in the resulting AVIF files.
- C++23 Compiler (GCC, Clang, or MSVC)
- CMake 3.28+
- libavif (for AVIF encoding)
- Exiv2 (for metadata processing)
(Note: stb_image and stb_image_resize2 are included in the repository as header-only libraries).
- Ensure you have the required dependencies installed (e.g., via
apt,brew, orvcpkg). - Clone the repository and run CMake:
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . -j"$(nproc)"You can easily integrate img2avif into your own CMake project using FetchContent:
include(FetchContent)
FetchContent_Declare(
img2avif
GIT_REPOSITORY https://github.com/youruser/img2avif.git
GIT_TAG main
)
FetchContent_MakeAvailable(img2avif)
# Link against the library
target_link_libraries(your_app PRIVATE img2avif::img2avif_lib)If you have installed the library on your system:
find_package(img2avif REQUIRED)
# Link against the library
target_link_libraries(your_app PRIVATE img2avif::img2avif_lib)Convert an image with default quality (90) and speed (3):
./build/img2avif input.jpg output.avifConvert with specific quality (0-100) and speed (0-10):
./build/img2avif input.png output.avif 85 4Generate AVIFs at 480w, 680w, 800w, 1024w, and 1280w sizes:
./build/img2avifs input.jpg out_prefix
# This will output:
# out_prefix_480.avif
# out_prefix_680.avif
# ...#include "Img2Avif.hpp"
#include <iostream>
int main() {
img2avif::ConversionOptions options;
options.quality = 80;
options.targetWidth = 1024; // 0 = keep original
auto result = img2avif::convert("input.jpg", "output.avif", options);
if (!result) {
std::cerr << "Failed: " << result.error() << "\n";
}
return 0;
}This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2026 ZHENG Robert
For a detailed history of changes, see the CHANGELOG.md.
Happy coding! 🚀 🖖