Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Img2Avif

C++23 library and command-line toolset for converting images to the modern AVIF format.

Report Issue · Request Feature

License Platform GitHub release (latest by date)


Table of Contents


Description

C++23 CMake Platform

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).

Features

  • C++23 Library (img2avif_lib): A reusable library providing a clean std::expected interface for AVIF conversion and resizing.
  • img2avif CLI: A fast 1:1 image to AVIF converter.
  • img2avifs CLI: 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.

Dependencies

  • 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).

Build Instructions

  1. Ensure you have the required dependencies installed (e.g., via apt, brew, or vcpkg).
  2. Clone the repository and run CMake:
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . -j"$(nproc)"

Integration

Using FetchContent (CMake 3.11+)

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)

Using find_package

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)

Example Usage

1:1 Conversion (img2avif)

Convert an image with default quality (90) and speed (3):

./build/img2avif input.jpg output.avif

Convert with specific quality (0-100) and speed (0-10):

./build/img2avif input.png output.avif 85 4

Multi-Size Responsive Generation (img2avifs)

Generate 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
# ...

Using the C++ Library

#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;
}

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

Copyright (c) 2026 ZHENG Robert

📄 Changelog

For a detailed history of changes, see the CHANGELOG.md.

Author

Zheng Robert - Core Development

Code Contributors

Contributors


Happy coding! 🚀 🖖

(back to top)

About

A high-performance C++23 library and command-line toolset for converting images to the modern AVIF format.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages