Created
August 1, 2024 05:19
-
-
Save bowber/478165ad0c257f2db7d53d2b8aefb279 to your computer and use it in GitHub Desktop.
Webp converter that auto convert every (*.jpg *.jpeg *.tif *.tiff *.png) files into webp and keep the original extension (OVERRIDE original files)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| setlocal enabledelayedexpansion | |
| set "PARAMS=-m 6 -q 70 -mt -af -progress" | |
| if not "%~1"=="" ( | |
| set "PARAMS=%*" | |
| ) | |
| rem Function to process a directory | |
| :process_dir | |
| set "DIR=%~1" | |
| cd /d "%DIR%" | |
| for %%f in (*.jpg *.jpeg *.tif *.tiff *.png) do ( | |
| rem Check if the file is already a WebP | |
| webpinfo "%%f" >nul 2>&1 | |
| if errorlevel 1 ( | |
| set "EXT=%%~xf" | |
| set "BASENAME=%%~nf" | |
| set "OUTFILE=!BASENAME!!EXT!" | |
| cwebp !PARAMS! "%%f" -o "!OUTFILE!" | |
| ) else ( | |
| echo Skipping "%%f" - already in WebP format. | |
| ) | |
| ) | |
| for /d %%d in (*) do ( | |
| if exist "%%d" ( | |
| call :process_dir "%%d" | |
| ) | |
| ) | |
| cd .. | |
| rem Return from function | |
| exit /b | |
| rem Start processing from the current directory | |
| call :process_dir "%cd%" | |
| echo Done. | |
| pause | |
| endlocal |
bowber
commented
Aug 1, 2024
Author
- Recursively loop through all folders in the same directory with this bat file
- Skip converted files
- Keep original file ext (override original files)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment