-
Notifications
You must be signed in to change notification settings - Fork 0
/
PNG-WebP.bat
76 lines (68 loc) · 1.62 KB
/
PNG-WebP.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
@echo off
SETlocal EnableExtensions
SETlocal EnableDelayedExpansion
TITLE WebP lossless batch converter - By 3DJ
SET InputFormat=PNG
pushd "%~dp0"
IF NOT "%~1"=="" (
IF EXIST "%~1/*" (
CD "%~1"
pushd "%~1"
SET "OutputPath=%~1\"
) ELSE (
For %%A in ("%~1") do (
CALL :Convert %%A "%%~dpA%%~nA.webp"
PAUSE
EXIT
)
)
)
ECHO.
ECHO Press any key to convert all the !InputFormat! files in this folder and subfolders
ECHO Output format: WebP lossless
IF DEFINED OutputPath (
ECHO Output folder: !OutputPath!
) ELSE (
ECHO Output folder: WebP\
)
ECHO Folder structure: Same as input relative path
ECHO.
ECHO - To generate WebP files in the same folder as the input files,
ECHO close this window and drag the folder/file into the .bat file.
ECHO - Existing WebP files will be skipped,
ECHO so you can stop and resume batch conversion later if needed.
PAUSE >NUL
ECHO.
FOR /R %%A in (*.*) do (
IF /I "%%~xA"==".!InputFormat!" (
SET "OutputPath=%%~dpA"
IF "%~1"=="" (
SET "OutputPath=%~dp0WebP\!OutputPath:%~dp0=!"
IF NOT EXIST "!OutputPath!" (
MKDIR "!OutputPath!"
)
)
CALL :Convert "%%A" "!OutputPath!%%~nA.webp"
)
)
ECHO Press any key to open the output folder
PAUSE
"!OutputPath!"
:Convert
IF NOT EXIST %2 (
CALL :Encode %1 %2
) ELSE (
For %%F in (%2) do (SET Filesize=%%~zF)
if !Filesize! EQU 0 (
ECHO %2 already exists, but seems corrupted/empty. Re-converting...
CALL :Encode %1 %2
) ELSE (
ECHO %2 already exists. Skipping...
)
)
EXIT /B
:Encode
ECHO Encoding %2
"%~dp0Converters/cwebp.exe" -v -mt -noasm -metadata all -progress -lossless -z 8 -m 6 -q 99 %1 -o %2
ECHO.
EXIT /B