Mass Convert Images to AVIF β€” Subfolders Included!

AVIFImageConversionImageOptimization

April 4, 2025

Image

πŸ”„ 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.

  1. Go to imagemagick.org
  2. Download the Windows version with legacy utilities and DLL support
  3. During installation:
  4. βœ… Enable "Add application directory to your system path"
  5. βœ… 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!

Sidak Vats

Β© 2025 Sidak Vats