1
0
Fork 0
isopod.cool/stuff/webpkiller/webpkiller.cmd

32 lines
1.2 KiB
Batchfile
Raw Normal View History

2023-01-09 21:30:45 +00:00
@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%