-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimize.bat
More file actions
72 lines (58 loc) · 1.58 KB
/
optimize.bat
File metadata and controls
72 lines (58 loc) · 1.58 KB
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
@echo off
setlocal enabledelayedexpansion
echo [INFO] Starting optimization process...
REM --all Support
if "%1"=="--all" (
echo [INFO] Running on all files recursively...
for /r %%i in (*.png) do (
set /a index+=1
echo [DEBUG] File index !index!: %%~i
call :process_file "%%~i"
)
goto :eof
)
REM Temporary file for storing file list
set "tempFile=%TEMP%\filelist.txt"
del "%tempFile%" >nul 2>&1
REM Generate the file list
(
git diff HEAD --name-only --diff-filter=ACMR
) > "%tempFile%"
echo [INFO] Temporary file content:
type "%tempFile%"
set "index=0"
REM Iterate through each file in the list
for /f "usebackq delims=" %%i in ("%tempFile%") do (
set /a index+=1
set "currentFile=%%i"
call :process_file "%%i"
)
REM Cleanup
del "%tempFile%" >nul 2>&1
echo [INFO] Optimization process completed!
exit /b
REM Subroutine for file processing
:process_file
setlocal
set "filePath=%~1"
REM Check if the file exists
if not exist "!filePath!" (
echo [WARN] File not found: "!filePath!"
endlocal
goto :eof
)
REM Skip non-PNG files
if /i not "!filePath:~-4!"==".png" (
echo [INFO] Skipping non-PNG file: "!filePath!"
endlocal
goto :eof
)
REM Optimize PNG files
echo [INFO] Running optipng on: "!filePath!"
optipng -o3 "!filePath!" >nul 2>&1
if errorlevel 1 echo [ERROR] optipng failed for "!filePath!"
echo [INFO] Running zopflipng on "!filePath!"
call zopflipng --iterations=15 --filters=0me --lossy_transparent -ym "!filePath!" "!filePath!" >nul 2>&1
if errorlevel 1 echo [ERROR] zopflipng failed for !filePath!
endlocal
goto :eof