Overview
Convert all your JPG, PNG, and WebP images — including files buried in subfolders — to AVIF on Windows using ImageMagick and a simple batch script. Smaller files, faster load times, zero quality loss.
If you're building a website or app, optimizing images is key to performance. AVIF offers super high compression (smaller file sizes than WebP or JPG), excellent image quality, and faster load times for your users. Here's how to convert your entire image library — including files buried in subfolders — to AVIF in one go on Windows.
- Super high compression — smaller file sizes than WebP or JPG.
- Excellent image quality — visually indistinguishable from the originals.
- Faster load times — lighter images mean snappier pages.
- Broad browser support — Chrome, Firefox, Safari 16+, and Edge all support it.
Download and install ImageMagick, the powerful image conversion tool. Go to imagemagick.org and 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 installing, confirm it's working by running this in your terminal:
magick -versionIf you see AVIF and WEBP listed in the output, you're good to go.
Place all your images (and subfolders of images) inside an input directory. Create a separate empty output folder where your converted AVIF files will land. For example:
C:\Users\You\Pictures\my-images ← source images
C:\Users\You\Pictures\converted-avif ← empty output folderOpen Notepad, paste the script below, and save it as convert-to-avif.bat. It walks every subfolder, converts each image, mirrors your directory structure in the output folder, and writes a log file when it's done.
@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- Double-click the .bat file.
- Watch the console show each image being converted.
- When done, open the log file in your output folder to see which images were converted, the start and end timestamps, and the total count.
The script doesn't dump everything into one flat folder. It mirrors your original directory layout. So if you had my-images\sub1\img1.jpg, you'll get converted-avif\sub1\img1.avif.
If you want to replace the originals rather than output to a separate folder, set INPUT_DIR and OUTPUT_DIR to the same path. The script below adds a safety check — it only deletes the original if the AVIF was successfully created, and only when the two directories match.
@echo off
setlocal enabledelayedexpansion
set "INPUT_DIR=C:\Users\You\Pictures\my-images"
set "OUTPUT_DIR=C:\Users\You\Pictures\my-images"
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"
if exist "%OUTPUT_DIR%!REL_PATH!!NAME!.avif" (
echo Converted: %%~F >> "%LOG_FILE%"
echo Converted: %%~F
set /a count+=1
if /i "%INPUT_DIR%"=="%OUTPUT_DIR%" (
del "%%~F"
echo Deleted original: %%~F >> "%LOG_FILE%"
)
) else (
echo Failed to convert: %%~F >> "%LOG_FILE%"
)
)
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%
pauseWant to push file sizes even lower? Add the -quality flag to the magick command inside the loop:
magick "%%~F" -quality 60 "%OUTPUT_DIR%!REL_PATH!!NAME!.avif"Quality ranges from 0 (smallest file, most lossy) to 100 (largest file, best quality). 60–80 is the sweet spot for most web images.
That's all it takes — ImageMagick and a batch file give you a fully automated, subfolder-aware AVIF conversion pipeline on Windows. Faster pages, better Core Web Vitals, and zero manual work for every image in your project.
