-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimageCompressToJpgDir.cmd
More file actions
47 lines (40 loc) · 1.44 KB
/
Copy pathimageCompressToJpgDir.cmd
File metadata and controls
47 lines (40 loc) · 1.44 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
@echo off
echo ###################################################
echo # Description: Compress all images in a directory to jpg, with a specified quality
echo # Usage: imageCompressToJpgDir.cmd /path/to/directory [quality] [width] [height]
echo # Param 1: Directory containing images
echo # Param 2 [Optional]: JPG quality (0-100, default: 85)
echo # Param 3 [Optional]: Width in pixels (for resize, maintains aspect ratio if used alone)
echo # Param 4 [Optional]: Height in pixels (for resize, used with width for exact dimensions)
echo # Requires: imagemagick, jpegoptim
echo ###################################################
echo.
REM Check parameters
IF "%~1"=="" (
echo Error: 1st arg must be a directory
exit /b 1
)
REM Verify input directory exists
IF NOT EXIST "%~1\" (
echo Error: Directory not found: %~1
exit /b 1
)
set "inputDir=%~1"
set "quality=%~2"
set "width=%~3"
set "height=%~4"
set "count=0"
echo Processing directory: %inputDir%
echo.
REM Process common image formats
for %%f in ("%inputDir%\*.png" "%inputDir%\*.jpg" "%inputDir%\*.jpeg" "%inputDir%\*.tif" "%inputDir%\*.tiff" "%inputDir%\*.bmp" "%inputDir%\*.webp" "%inputDir%\*.heic" "%inputDir%\*.heif" "%inputDir%\*.avif") do (
if exist "%%f" (
echo ---
call "%~dp0imageCompressToJpg.cmd" "%%f" %quality% %width% %height%
set /a count+=1
echo.
)
)
echo ===================================
echo Done! Processed %count% image(s).
exit /b 0