Language: EN

como-convertir-imagenes-a-avif

How to Convert Images to AVIF Format Using avif-cli

Avif-cli is a command-line tool that allows us to convert images to AVIF format quickly and easily.

The AVIF image format (AV1 Image File Format) is becoming increasingly popular due to its high compression capacity and superior quality compared to other formats like JPEG and PNG, and even WebP.

Avif-cli is based on sharp, an image processing library capable of handling large images and batch conversions.

Although AVIF is gaining support, it is still not compatible with all browsers and devices. Make sure to provide alternatives like JPEG or PNG or even WEBP on your website.

Installing avif-cli

To use Avif-cli, you first need to install it globally using NPM (the Node.js package manager):

npm install -g avif-cli

This command will install Avif-cli and make it accessible from anywhere.

Using Avif-cli

Basic Conversion

To convert a single image, use the following command:

avif input.jpg -o output.avif

Here, input.jpg is the image you want to convert, and output.avif is the name of the converted file.

Advanced Options

Avif-cli offers a wide range of options that allow you to control specific aspects of the conversion.

ParameterDescriptionDefault Value
--inputInput file name(s)*.{jpg,jpeg,tif,tiff,webp,png,gif,svg}
--outputOutput directory, defaults to the same directory as input""
--qualityQuality vs file size, from 1 (lowest) to 100 (highest)50
--effortCPU effort vs file size, from 0 (faster/larger) to 9 (slower/smaller)4
--losslessUse lossless compressionfalse
--chroma-subsamplingChroma subsampling, options: ‘4:2:0’ (subsampling) or ‘4:4:4’ (no subsampling)4:4:4
--keep-metadataKeep all metadatafalse
--overwriteAllow overwriting existing output filesfalse
--append-extAdd .avif to the file name instead of replacing the current extensionfalse
--verboseWrite progress to stdoutfalse
-h, --helpShow helpfalse
--versionShow version numberfalse

Converting a Complete Directory

To convert all images in a directory, you can use the following command:

avif /path/to/directory/* -o /path/to/output/

This will convert all images in the specified directory to AVIF format and save them in the indicated output folder.

Batch Convert Multiple Images

If you have several images you want to convert, you can do so in batch using the following command:

avif *.jpg -o output/

This command converts all images with the .jpg extension in the current directory to AVIF format and saves the converted files in a directory called output.

Adjusting Compression Quality

You can control the quality of the resulting AVIF image by adjusting the quality parameter. The quality value can range from 0 (worst quality and highest compression) to 100 (best quality and lowest compression).

avif input.jpg -o output.avif -q 40

In this example, the image quality has been set to 40%.