-
Notifications
You must be signed in to change notification settings - Fork 0
/
wss.sh
executable file
·85 lines (61 loc) · 1.63 KB
/
wss.sh
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
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -o noglobe
# A POSIX variable
OPTIND=0 # Reset in case getopts has been used previously in the shell.
# Temporary filename pattern
TEMP_FILE_PATTERN="sw_%d.sw"
echo [WSS] Checking parameters...
while [[ $# > 1 ]]; do
key="$1"
case $key in
-i|--input)
input="$2"
shift
;;
-w|--width)
width="$2"
shift
;;
-h|--height)
height="$2"
shift
;;
-o|--order)
order="$2"
shift
;;
*)
# unknown option
;;
esac
shift
done
input=( ${input} )
[ ${#input[@]} -eq 0 ] && echo "Missing 'input' argument or no input files match the wildcard" && exit 1
[ -z $input ] && echo "Missing 'input' argument" && exit 1
[ -z $width ] && echo "Missing 'width' argument" && exit 1
[ -z $height ] && echo "Missing 'height' argument" && exit 1
[ -z $order ] && echo "Missing 'order' argument" && exit 1
for file in "${input[@]}"; do
file_base="${file##*/}"
file_ext="${file_base##*.}"
file_name="${file_base%.*}"
file_dest="${file_name}.out.${file_ext}"
echo "[WSS] Processing file: ${file_name}.${file_ext} to ${file_dest}"
echo "[WSS] Splitting..."
convert -crop "${width}x${height}" +repage "${file}" "${TEMP_FILE_PATTERN}"
append_command="convert +append"
IFS=', ' read -a orders <<< "$order"
for i in "${orders[@]}"; do
i=$((i - 1))
tile_file_name=${TEMP_FILE_PATTERN//%d/${i}}
append_command="${append_command} ${tile_file_name}"
done
append_command="${append_command} ${file_dest}"
echo "[WSS] Joining..."
$append_command
echo "[WSS] Deleting temporary files..."
rm -rf ./${TEMP_FILE_PATTERN//%d/*}
echo "[WSS] Done."
done
echo "[WSS] All done."