DEV Community

Michael Smith
Michael Smith

Posted on

Ways to Compress AVIF

AVIF is a relatively new image format that has quickly gained popularity for its impressive compression capabilities without sacrificing quality. However, even though AVIF is inherently efficient, there are still ways to optimize it further, especially if you're aiming to squeeze every last byte out of your images. Let's explore some non-traditional ways to compress AVIF files and get the most out of this format.

AVIF is fantastic for delivering high-quality images with smaller file sizes compared to other formats, but there’s always room for more optimization, particularly when dealing with lots of images on a busy website.

Online Tools for Quick Compression

One of the simplest ways to compress AVIF files is by using online tools. Platforms like Squoosh, AVIF.io, and Compress-Or-Die make it incredibly easy to get started:

Simply upload your AVIF file, choose your compression level, and download the optimized version.

These tools are particularly useful if you need a fast solution and don't want to deal with complex software installations.

This option is ideal for those looking for a quick and hassle-free way to make their AVIF images smaller.

Using Image Editing Software

If you want more control over how your AVIF files are compressed, using software like GIMP or Photoshop (with plugin) can help. While Photoshop doesn’t natively support AVIF, there are plugins available that enable it.

- GIMP: Open your AVIF file in GIMP, and use File > Export As to save the image with different compression settings. Lowering the quality slider helps decrease the file size without a dramatic loss in quality.
- Photoshop with Plugin: Install an AVIF plugin, open your file, and tweak compression settings using Save As or Export options.

These methods provide more granular control, allowing you to strike the perfect balance between quality and file size.

Command-Line Magic for Batch Compression

For those who like to work in a terminal environment, avifenc is an excellent tool for compressing AVIF files via the command line. This tool is part of the libavif library and gives you plenty of options for fine-tuning compression.

Install libavif on your system.

Run a command like:

This command allows you to set minimum and maximum quality values, giving you control over the compression process. It’s especially useful for batch processing multiple images and ensures consistent results across all your AVIF files.

Tweaking AVIF Settings for Maximum Compression

- Reduce Bit Depth: AVIF supports different bit depths, and reducing the bit depth can save a significant amount of space. If your image doesn’t need high fidelity, consider reducing it from 10-bit to 8-bit.
- Lower Quality Settings: AVIF compression allows you to set the quality level, typically between 0-100. Experiment with lower values to see how much size reduction you can achieve while maintaining acceptable visual quality.
- Reduce Image Resolution: If the image resolution can be lowered without impacting the use case, resizing the image is a highly effective way to reduce the file size.

Automation with Scripts

If you find yourself frequently compressing AVIF files, scripting the process can save time. Using tools like Python with bindings for libavif, you can automate the compression of entire directories of images with just a single command.

For instance, a basic Python script can use subprocess to call avifenc for each image, making your workflow more efficient.

Final Musings

AVIF is already a highly efficient format, but there’s always a way to make it better. By using the right combination of tools—be it online platforms, software like GIMP or Photoshop, command-line utilities, or even automation scripts—you can make sure your AVIF files are as light as possible without compromising on quality.

The key to compressing AVIF effectively lies in experimenting with different settings to understand what works best for your particular images. Whether you need a quick fix or a more controlled approach, these methods will help you keep your AVIF files lean and mean, ready to deliver an excellent experience for your users.

Top comments (0)