Converting Images to AVIF on Linux, Including JPG, PNG, and WebP Formats

The AVIF (AV1 Image File Format) is gaining popularity for its impressive compression capabilities without sacrificing image quality, making it a preferred choice for web developers and photographers alike. This guide explores various methods to convert images to AVIF format on Linux, enabling users to leverage this advanced image format’s benefits.

In this tutorial you will learn:

  • How to install and use different tools for converting images to AVIF
  • Steps to convert images using command-line tools and graphical applications
Converting Images to AVIF on Linux, Including JPG, PNG, and WebP Formats
Converting Images to AVIF on Linux, Including JPG, PNG, and WebP Formats
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Linux distribution (e.g., Ubuntu, Fedora)
Software libavif-bin, ffmpeg, ImageMagick, GIMP
Other Basic command line and graphical interface usage knowledge
Conventions # – indicates commands that require root privileges, executed as root or with sudo
$ – indicates commands for regular non-privileged users

Efficient Methods for AVIF Image Conversion on Linux

Flexible Image Conversion to AVIF

For converting images to AVIF format, replace ‘image.png’ in the examples below with your desired image file, regardless of its format (e.g., ‘image.jpg’, ‘image.bmp’. ‘image.gif’).

Converting your images to AVIF can significantly reduce file sizes while maintaining high-quality visuals. Here are several methods to achieve this on a Linux system.

The AVIF (AV1 Image File Format) is a cutting-edge image format engineered for remarkable compression efficiency while maintaining high image quality. Leveraging the AV1 video codec technology, it offers superior lossy and lossless compression, making it a strong competitor to established formats like JPEG,PNG and even WebP, particularly in web contexts where bandwidth and loading times are critical. AVIF’s support for a wide color gamut, high dynamic range (HDR), and progressive rendering enhances the visual experience, promising a future where images are both beautifully detailed and efficiently delivered.
  1. Converting with libavif-bin: Start by installing the libavif-bin package.
    $ sudo apt install libavif-bin
    $ avifenc image.png image_avifenc.avif

    For more control over the output:

    $ avifenc --min 30 --max 63 --speed 10 --yuv 420 -d 8 --codec aom image.png image_avifenc2.avif

    Here’s a breakdown of what each part of the above command does:

    avifenc is the command-line utility used to encode images into the AVIF format. It is part of the libavif package, which provides tools for working with AVIF images.

    –min 30 sets the minimum quantizer for the AV1 codec. Quantizers control the compression level, with lower values resulting in higher quality and larger file sizes. A minimum quantizer of 30 strikes a balance between file size and quality.

    –max 63 defines the maximum quantizer for the codec. This setting caps the amount of compression, ensuring that the quality does not drop below a certain threshold. The maximum value of 63 allows for significant compression, beneficial for reducing file sizes at the cost of some quality.

    –speed 10 adjusts the encoding speed. The speed parameter ranges from 0 (slowest) to 10 (fastest), affecting both the encoding time and the output file’s quality and size. A speed of 10 optimizes the encoding process for faster completion, which might slightly compromise the final image quality and compression efficiency.

    –yuv 420 specifies the chroma subsampling format. YUV 4:2:0 is a type of chroma subsampling that reduces the color information in the image to decrease the file size without significantly affecting perceived quality. This setting is common in digital video and photography compression.

    -d 8 sets the depth of the color channels in bits. A depth of 8 bits per channel is standard and sufficient for a wide range of colors, supporting up to 16.7 million colors in total. This is typically adequate for most applications, balancing color fidelity with file size.

    –codec aom chooses the AV1 codec provided by the Alliance for Open Media (AOM). This codec is responsible for the actual compression and encoding of the image into the AVIF format. It’s known for its high efficiency and quality at various bitrates.

    image.png is the source image file that you wish to convert. This command is flexible and supports multiple input formats, including PNG, JPG, and JPEG.

    image_avifenc2.avif is the name of the output file in the AVIF format. This is where the converted image will be saved, ready for use in applications that support the AVIF format.

    This method directly utilizes the AVIF encoding library to convert images. Advanced options allow for customization of encoding settings.

  2. Converting with ffmpeg: Ensure ffmpeg is installed on your system.
    $ sudo apt install ffmpeg

    Now you are ready to convert your image to AVIF

    $ ffmpeg -i image.png -c:v libaom-av1 -crf 30 -pix_fmt yuv420p image_ffmpeg.avif

    This command is especially useful for users looking to leverage ffmpeg’s extensive encoding capabilities for creating AVIF images. Below is an explanation of each component of the command:

    ffmpeg is the command that invokes the ffmpeg software, a comprehensive multimedia processing tool. It is widely used for video and audio conversion, processing, and streaming tasks.

    -i input.png specifies the input file. In this case, input.png is the name of the image file you wish to convert to AVIF. While the example uses a PNG file, ffmpeg can work with a wide variety of image and video formats as input.

    -c:v libaom-av1 indicates the codec to be used for the video (or in this case, image) conversion. libaom-av1 is an open-source AV1 codec provided by the Alliance for Open Media. This codec is chosen for its efficiency in encoding images or videos into the AVIF or AV1 formats, respectively, offering high compression efficiency and quality.

    -crf 30 sets the Constant Rate Factor (CRF) value to 30, which controls the output file’s quality. CRF is a parameter that balances the compression level and quality, where lower values result in better quality (and larger file sizes) and higher values produce more compression (but lower quality). A CRF of 30 is often used as a compromise between image quality and file size.

    -pix_fmt yuv420p defines the pixel format to be used in the output file. yuv420p specifies YUV color space with 4:2:0 chroma subsampling. This setting is typical for digital images and videos, reducing file size by sampling color information at a lower resolution than luminance. It is a widely supported format that balances quality with compression efficiency.

    image_ffmpeg.avif is the name of the output file. This part of the command specifies that the resulting file from the conversion process should be saved as image_ffmpeg.avif, adopting the AVIF format. The use of the AVIF extension tells ffmpeg to encode the output in the AVIF format, utilizing the previously specified codec and settings.

    ffmpeg is a powerful tool that supports a wide range of formats, including AVIF. The command above converts an image to AVIF using specific codec settings.

  3. Converting with ImageMagick: First, install ImageMagick.
    $ sudo apt install imagemagick

    Next, convert to AVIF using imagemagick

    $ convert image.png image_imagemagick.avif

    Alternatively, you can futher try to reduce the file size while reducing the image quality:

    $ convert image.png -quality 20 -define avif:speed=10 image_imagemagick2.avif

    The above command leverages ImageMagick, a versatile command-line tool used for image conversion, editing, and processing, to create AVIF images. This command provides a straightforward method for users to convert existing images to the AVIF format, balancing quality and encoding speed. Below is an exploration of the command’s components:

    convert is the primary command used by ImageMagick for image conversion and processing. It reads, converts, and writes images in a variety of formats.

    image.png specifies the input file for the conversion. In this example, it’s a PNG image, but ImageMagick’s convert command can handle a broad range of image formats as input.

    -quality 20 sets the quality level of the output image. In ImageMagick, the -quality option generally controls the compression level for the output file. For AVIF images, lower values result in higher compression, which means smaller file sizes at the cost of some loss in image quality. A quality setting of 20 is quite low, indicating that the image will be significantly compressed, making it useful for scenarios where minimizing file size is a priority over maintaining high image fidelity.

    -define avif:speed=10 is an ImageMagick option that passes specific encoding parameters to the AVIF encoder. Here, avif:speed=10 adjusts the encoding speed for the AVIF conversion process. Speed values can range from slower settings, which prioritize image quality and compression efficiency, to faster settings, which reduce encoding time at the expense of some quality. A speed setting of 10 is on the faster end of the scale, indicating that the conversion will prioritize speed over the utmost quality and compression.

    image_imagemagick2.avif denotes the name of the output file. This part of the command indicates that the converted image should be saved with this name, using the AVIF format. The use of the .avif extension specifies that the output file will be encoded in the AVIF format, benefiting from the specified quality and speed settings.

    This command showcases how ImageMagick can be used to convert images to the AVIF format, providing users with control over the quality and speed of the conversion process. It’s a powerful option for users looking to optimize their images for web or storage, making use of AVIF’s advantages in terms of compression efficiency and image quality.

    ImageMagick provides a straightforward command to convert images. It’s versatile and supports numerous formats, including AVIF.

  4. Converting with GIMP: For users preferring a graphical interface, GIMP is a free and open-source image editor that supports AVIF through plugins.
    1. Open GIMP and load your image.
    2. Click File > Export As.
    3. Choose AVIF from the file format dropdown.
    4. Adjust the settings as desired.
    5. Click Export to save your AVIF image.

    This method is ideal for users who wish to visually adjust and convert images without using the command line.


Respective image file sizes after conversion
Respective image file sizes after conversion
Image quality comparison after conversion to AVIF
Image quality comparison after conversion to AVIF although not very visible on such small images.


Converting images to AVIF on Linux is straightforward, thanks to a variety of tools catering to different preferences, from command-line utilities to graphical applications. Whether you prioritize automation and scripting or manual control and visual interfaces, Linux offers robust solutions for incorporating AVIF into your workflow, ensuring efficient use of bandwidth and storage without compromising image quality.

Frequently Asked Questions About Converting Images to AVIF on Linux

1. What is AVIF and why is it considered superior to formats like JPEG or PNG?

AVIF, or AV1 Image File Format, is a new image format that utilizes the AV1 video codec for highly efficient compression. It offers significantly better compression than JPEG or PNG, resulting in smaller file sizes without compromising image quality, making it superior for web and storage purposes.

2. Can I convert GIFs to AVIF format?

Yes, you can convert GIFs to AVIF format using tools like ffmpeg or ImageMagick on Linux, which can help reduce file size while maintaining or even improving image quality.

3. Is there any quality loss when converting images to AVIF?

When converting images to AVIF, you can expect minimal to no perceptible quality loss. AVIF’s compression algorithm is designed to maintain high image fidelity, even at lower file sizes.

4. How do I batch convert multiple images to AVIF?

You can batch convert images using command-line tools like ffmpeg or ImageMagick by scripting commands to process multiple files in a directory, enhancing efficiency and saving time.

5. Are there any web browsers that do not support AVIF images?

As of now, most modern web browsers support AVIF images, including Chrome, Firefox, and Edge. However, some older browsers or versions may not support AVIF format yet.

6. What are the best settings for converting images to AVIF for web use?

For web use, aiming for a balance between file size and quality is key. A moderate quality setting (e.g., -quality 50 in ImageMagick) and default encoding speed usually offer a good balance for web images.

7. Can AVIF handle transparency?

Yes, AVIF supports transparency, making it a versatile format for various types of images, including those requiring alpha channels.

8. How does AVIF compare to WebP in terms of compression and quality?

AVIF generally provides better compression and quality than WebP, especially at lower bitrates. This makes AVIF more suitable for high-quality images on the web.

9. What tools are available for viewing AVIF images on Linux?

Several image viewers and browsers on Linux support AVIF, such as GNOME Image Viewer (Eye of GNOME) and browsers like Firefox and Chrome.

10. How can I ensure the highest quality when converting to AVIF?

To ensure the highest quality, use the lowest compression settings (highest quality value) and take advantage of AVIF’s advanced options, such as specifying color depth and chroma subsampling settings.

11. Is it possible to revert an AVIF image back to its original format?

While you can convert AVIF images back to other formats like PNG or JPEG, it’s important to note that this conversion might not perfectly restore the original file due to the compression and encoding process.

Comments and Discussions
Linux Forum