-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcropImageDirCentered.cmd
More file actions
62 lines (49 loc) · 1.43 KB
/
Copy pathcropImageDirCentered.cmd
File metadata and controls
62 lines (49 loc) · 1.43 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
@echo off
echo ###################################################
echo # Description: Crop images in a directory to be centered
echo # Usage: cropImageDirCentered.cmd C:\path\to\images 640 480
echo # Param 1: Directory of images
echo # Param 2: New width
echo # Param 3: New height
echo # Requires: ImageMagick
echo ###################################################
echo.
REM Check parameters
IF "%~1"=="" (
echo Error: 1st arg must be a directory
exit /b 1
)
IF "%~2"=="" (
echo Error: 2nd arg must be width
exit /b 1
)
IF "%~3"=="" (
echo Error: 3rd arg must be height
exit /b 1
)
REM Set variables
set "directory=%~1"
set "width=%~2"
set "height=%~3"
REM Validate directory exists
IF NOT EXIST "%directory%\" (
echo Error: Directory not found: %directory%
exit /b 1
)
echo Processing images in %directory% to %width%x%height%
REM Loop through image files
FOR %%i IN ("%directory%\*.jpg" "%directory%\*.png" "%directory%\*.jpeg" "%directory%\*.gif") DO (
CALL :ProcessImage "%%i" %width% %height%
)
echo Success: All images processed
exit /b 0
:ProcessImage
REM Process a single image
set "filename=%~1"
set "width=%~2"
set "height=%~3"
set "outputFile=%~dpn1.crop.%width%x%height%%~x1"
echo Cropping image: %filename% to %width%x%height%
REM Do conversion - gravity center crops from the center
magick convert "%filename%" -gravity center -resize %width%x%height%^ -extent %width%x%height% "%outputFile%"
exit /b 0