Convert to AVIF using the CLI

The AVIF image format offers amazing size and quality improvements over PNG and JPG.

Converting existing images to AVIF is easy to script on the command line using the right tool. On Debian-based systems, the process is easy using apt-get.

★  ~ % sudo apt install libavif-bin
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libavif13 libgav1-0 libyuv0
The following NEW packages will be installed:
  libavif-bin libavif13 libgav1-0 libyuv0

With the avifenc command installed, converting images is easy and results in impressive reductions in file size (625k -> 62k 🤯)!

★  Pictures/Screenshots % avifenc avif-image-uploaded-to-wordpress-media-library.png avif-image-uploaded-to-wordpress-media-library.avif
Successfully loaded: avif-image-uploaded-to-wordpress-media-library.png
AVIF to be written: (Lossy)
 * Resolution     : 1600x900
 * Bit Depth      : 8
 * Format         : YUV444
 * Alpha          : Not premultiplied
 * Range          : Full
 * Color Primaries: 1
 * Transfer Char. : 13
 * Matrix Coeffs. : 6
 * ICC Profile    : Absent (0 bytes)
 * XMP Metadata   : Absent (0 bytes)
 * EXIF Metadata  : Absent (0 bytes)
 * Transformations: None
 * Progressive    : Unavailable
Encoding with AV1 codec 'aom' speed [6], color QP [24 (Medium) <-> 26 (Medium)], alpha QP [0 (Lossless) <-> 0 (Lossless)], tileRowsLog2 [0], tileColsLog2 [0], 1 worker thread(s), please wait...
Encoded successfully.
 * Color AV1 total size: 62961 bytes
 * Alpha AV1 total size: 0 bytes
Wrote AVIF: avif-image-uploaded-to-wordpress-media-library.avif
★  Pictures/Screenshots % ls -alh avif*
-rw-rw-r-- 1 benjamin benjamin  62K Jul 27 11:49 avif-image-uploaded-to-wordpress-media-library.avif
-rw-rw-r-- 1 benjamin benjamin 645K Jul 27 11:43 avif-image-uploaded-to-wordpress-media-library.png

An example of the WordPress media library editing an AVIF image.

Posted

in

by

Tags: