Last active
October 23, 2023 17:03
-
-
Save jimmyctk/18dcb0c49cadbbd9c41663bedab13b07 to your computer and use it in GitHub Desktop.
Drag and drop batch webp convert to png using dwebp on Windows
This file contains 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 | |
:: Check if the number of arguments is less than 2 | |
if "%~1" == "" ( | |
echo Usage: %0 "Path to dwebp.exe" [Input files/directories...] | |
exit /b | |
) | |
:: Set the path to dwebp.exe | |
set dwebp_path="%~1" | |
shift | |
:: Loop through all input arguments | |
:process_arg | |
if "%~1" == "" ( | |
goto :eof | |
) | |
:: Check if the argument is a directory | |
if exist "%~1\" ( | |
:: If it's a directory, convert all WebP files inside the directory to PNG | |
for %%F in ("%~1\*.webp") do ( | |
echo Converting "%%~F" to "%%~dpnF.png" | |
%dwebp_path% "%%~F" -o "%%~dpnF.png" | |
) | |
) else ( | |
:: If it's a file, check if it's a WebP file and convert it to PNG | |
if /i "%~x1" == ".webp" ( | |
echo Converting "%~1" to "%~dpn1.png" | |
%dwebp_path% "%~1" -o "%~dpn1.png" | |
) else ( | |
echo Skipping non-WebP file: "%~1" | |
) | |
) | |
:: Shift to the next argument | |
shift | |
goto :process_arg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment