@echo off

::Set variable filepath to the first argument
SET filepath=%~f1

::Abort if the given file doesn't exist
IF NOT EXIST "%filepath%" (
    ECHO %~n0: file not found - %filepath% >&2
    EXIT /B 1
)

::Replace all instances of .webp with .png in the filename. kind of banking on the user not putting the extension anywhere else in the file or folder names for this to work properly...
::I should be finding the last period in the filename and replacing everything AFTER it with the extension I want, but can't figure out how to do that because Windows batch is a nightmare language
::You can replace this with "SET outfile=%filepath%.png" (no quotes) if that bothers you more than double file extensions
::You can replace these two file extensions with any two image types you want to do this with
SET outfile=%filepath:.webp=.png%

::Abort if filename.png already exists
IF EXIST "%outfile%" (
    ECHO %~n0: %outfile% already exists. Aborting...
    EXIT /B 2
)

::Use ImageMagick's command line tools to generate the converted file
magick "%filepath%" "%outfile%"

::Delete the original file (optional, this can be removed if for some reason you want to keep the shitty gross webp)
del "%filepath%"

::Open the new, fixed image like nothing ever happened
%outfile%
