Skip to content

Instantly share code, notes, and snippets.

@jimmyctk
Last active October 23, 2023 17:03
Show Gist options
  • Save jimmyctk/18dcb0c49cadbbd9c41663bedab13b07 to your computer and use it in GitHub Desktop.
Save jimmyctk/18dcb0c49cadbbd9c41663bedab13b07 to your computer and use it in GitHub Desktop.
Drag and drop batch webp convert to png using dwebp on Windows
@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