forked from i0ntempest/waifu2x-macos-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto-waifu2x-moveimg.sh
More file actions
executable file
·72 lines (70 loc) · 2.81 KB
/
auto-waifu2x-moveimg.sh
File metadata and controls
executable file
·72 lines (70 loc) · 2.81 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
#!/usr/bin/env sh
#
# Copyright 2019-2022 Zhenfu Shi (i0ntempest)
# Version 0.1.0
#
move() {
if [ ! -d "$1" ]; then
echo "Input is not a directory!" >&2
exit 1
fi
[ -d ~/Pictures/waifu2x/1.5x ] || mkdir -p ~/Pictures/waifu2x/1.5x
[ -d ~/Pictures/waifu2x/2x ] || mkdir -p ~/Pictures/waifu2x/2x
[ -d ~/Pictures/waifu2x/3x ] || mkdir -p ~/Pictures/waifu2x/3x
[ -d ~/Pictures/waifu2x/4x ] || mkdir -p ~/Pictures/waifu2x/4x
[ -d ~/Pictures/waifu2x/Output ] || mkdir -p ~/Pictures/waifu2x/Output
# Your monitor width
master_res_width=3840
crit4x_width=$(awk -v num="$master_res_width" 'BEGIN { print (num/3) }')
crit3x_width=$(awk -v num="$master_res_width" 'BEGIN { print (num/2) }')
crit2x_width=$(awk -v num="$master_res_width" 'BEGIN { print (num/1.5) }')
errors=0
total=0
cntnoprocess=0
cnt1_5x=0
cnt2x=0
cnt3x=0
cnt4x=0
for file in "$1"/*; do
echo "Processing: ""$file"
local width=$(identify -format "%w" "$file")
if [ "$?" != 0 ] || [ -z "$width" ]; then
errors=$(awk -v num="$errors" 'BEGIN { print (num+1) }')
continue
fi
if [ "$(awk -v width="$width" -v crit="$crit4x_width" 'BEGIN { print (width<crit) }')" -eq 1 ]; then
mv "$file" ~/Pictures/waifu2x/4x/
cnt4x=$(awk -v num="$cnt4x" 'BEGIN { print (num+1) }')
elif [ "$(awk -v width="$width" -v crit="$crit3x_width" 'BEGIN { print (width<crit) }')" -eq 1 ]; then
mv "$file" ~/Pictures/waifu2x/3x/
cnt3x=$(awk -v num="$cnt3x" 'BEGIN { print (num+1) }')
elif [ "$(awk -v width="$width" -v crit="$crit2x_width" 'BEGIN { print (width<crit) }')" -eq 1 ]; then
mv "$file" ~/Pictures/waifu2x/2x/
cnt2x=$(awk -v num="$cnt2x" 'BEGIN { print (num+1) }')
elif [ "$(awk -v width="$width" -v crit="$master_res_width" 'BEGIN { print (width<crit) }')" -eq 1 ]; then
mv "$file" ~/Pictures/waifu2x/1.5x/
cnt1_5x=$(awk -v num="$cnt1_5x" 'BEGIN { print (num+1) }')
else
cntnoprocess=$(awk -v num="$cntnoprocess" 'BEGIN { print (num+1) }')
fi
total=$(awk -v num="$total" 'BEGIN { print (num+1) }')
done
echo "Summary:"
echo "Successfully processed ""$total"" images"
echo "No upscaling needed for ""$cntnoprocess"" image(s), not moved"
echo "Moved ""$cnt1_5x"" image(s) for 1.5x upscale"
echo "Moved ""$cnt2x"" image(s) for 2x upscale"
echo "Moved ""$cnt3x"" image(s) for 3x upscale"
echo "Moved ""$cnt4x"" image(s) for 4x upscale"
if [ "$errors" -ne 0 ]; then
echo "Encountered ""$errors"" errors during processing" >&2
exit 2
fi
}
if [ -z "$1" ]; then
echo "Input or drag a directory containing images:"
read imgpath
move "$imgpath"
else
move "$1"
fi