Mass Convert Images to AVIF β Subfolders Included!
April 4, 2025

π How to Convert All Your Images (Even in Subfolders!) to AVIF on Windows Using ImageMagick πΌοΈπ
π§ Why Convert to AVIF?
If you're building a website or app, optimizing images is key to performance. Thatβs where AVIF comes in β it offers:
- π₯ Super high compression (smaller file sizes than WebP or JPG)
- πΌοΈ Excellent image quality
- β‘οΈ Faster load times for your users
But how do you convert all your .jpg, .png, .webp files β including those buried in subfolders β into .avif in one go?
Letβs do it like pros π»
π οΈ Step 1: Install ImageMagick
First, download and install ImageMagick, the powerful image conversion tool.
- Go to imagemagick.org
- Download the Windows version with legacy utilities and DLL support
- During installation:
- β Enable "Add application directory to your system path"
- β Install WebP and AVIF support if prompted
After it installs, check it's working:
magick -version
If you see AVIF and WEBP in the output β youβre golden π
π Step 2: Organize Your Image Folder
Letβs say your images are in this structure:
C:\Users\You\Pictures\my-images βββ image1.jpg βββ subfolder β βββ image2.png βββ deeper\more βββ image3.webp
Create an empty output folder:
C:\Users\You\Pictures\converted-avif
π‘ Step 3: The Magic Batch Script
Create a .bat file that automates the whole thing β and even recreates your folder structure!
1. Open Notepad and paste this:
@echo off setlocal enabledelayedexpansion set "INPUT_DIR=C:\Users\You\Pictures\my-images" set "OUTPUT_DIR=C:\Users\You\Pictures\converted-avif" set /a count=0 set "LOG_FILE=%OUTPUT_DIR%\conversion-log.txt" echo Converting images to AVIF > "%LOG_FILE%" echo Started at: %DATE% %TIME% >> "%LOG_FILE%" echo. >> "%LOG_FILE%" for /r "%INPUT_DIR%" %%F in (*.jpg *.jpeg *.png *.webp) do ( set "FILE=%%~F" set "EXT=%%~xF" set "NAME=%%~nF" set "REL_PATH=%%~dpF" set "REL_PATH=!REL_PATH:%INPUT_DIR%=!" if not exist "%OUTPUT_DIR%!REL_PATH!" ( mkdir "%OUTPUT_DIR%!REL_PATH!" ) magick "%%~F" "%OUTPUT_DIR%!REL_PATH!!NAME!.avif" echo Converted: %%~F >> "%LOG_FILE%" echo Converted: %%~F set /a count+=1 ) echo. >> "%LOG_FILE%" echo Finished at: %DATE% %TIME% >> "%LOG_FILE%" echo Total images converted: !count! >> "%LOG_FILE%" echo. echo β Done! Total images converted: !count! echo π Log saved to: %LOG_FILE% pause
2. Save it as:
convert-to-avif.bat
π Step 4: Run It Like a Boss
- β Double-click the .bat file
- β³ Watch the console show each image being converted
- π When done, check the log file in your output folder to see:
- Which images were converted
- When it started and ended
- How many total
π Bonus: Preserves Folder Structure
Yup, this script doesnβt just dump files in one place β it keeps your original folder layout. So if you had:
my-images\sub1\img1.jpg
You'll get:
converted-avif\sub1\img1.avif
π Optional: Control Compression
Want to reduce file size more? Add the -quality flag like this:
magick "%%~F" -quality 60 "%OUTPUT_DIR%!REL_PATH!!NAME!.avif"
Adjust quality (0 = smallest, 100 = best).
π£ Thatβs a Wrap!
Now youβve got lightning-fast .avif images and a fully automated conversion flow β even for deep folder structures. All thanks to the power of ImageMagick and a little batch scripting magic π«
π¬ Got Questions?
Drop them in mail!