Of course. The convert command, part of the ImageMagick suite, is perfect for this.
The Command
Here is the command to convert a single file:
convert input.avif -resize 1280x -quality 50 output.avif
Command Breakdown
convert: The ImageMagick command-line tool for image conversion and manipulation.
input.avif: Your source AVIF file.
-resize 1280x: This resizes the image.
1280: The target width in pixels.
x: By leaving the height empty, ImageMagick will automatically calculate it to maintain the original aspect ratio.
-quality 50: This sets the compression quality for lossy formats. The scale is typically 1-100, where a lower number means higher compression and lower quality. 50 is a good starting point for a significant size reduction.
output.avif: The name of the new, converted file. The .avif extension tells ImageMagick to encode the output in the AVIF format.
Important Prerequisite: Check for AVIF Support
Your version of ImageMagick must be compiled with support for AVIF (usually via the libheif or libaom library). You can check if your installation supports it with this command:
magick identify -list format | grep -i AVIF
If you get output like this, you're good to go:
AVIF* HEIC AV1 Image File Format (1.12.0)
The * next to AVIF indicates read/write support. If you get no output, you'll need to install or update ImageMagick and its dependencies. On Debian/Ubuntu, you might need libheif-examples, and on macOS with Homebrew, brew install imagemagick should include it.
Batch Processing Multiple Files
If you have many .avif files to convert, you can use a simple for loop in your shell.
-
First, create a directory for the output files to keep things clean.
mkdir converted_images
-
Then, run the loop. This command finds every .avif file in the current directory and processes it, saving the result in converted_images.
for file in *.avif; do
echo "Converting $file..."
convert "$file" -resize 1280x -quality 50 "converted_images/$file"
done
Note: Using quotes around "$file" is important to correctly handle filenames that contain spaces.