-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path076-remove-thumbnails.sh
More file actions
executable file
·74 lines (53 loc) · 1.36 KB
/
Copy path076-remove-thumbnails.sh
File metadata and controls
executable file
·74 lines (53 loc) · 1.36 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
73
74
#!/usr/bin/env bash
cd "$(dirname "$0")"
datetime=$(date -Is | tr : -)
tmp=$(basename "$0" .sh).tmp.$datetime
src=070-deskew
dst=070-deskew # replace files
bak=070-deskew.bak.$datetime
# scan_format=tiff
source 030-measure-page-size.txt
function check_command() {
if ! command -v "$1" &>/dev/null; then
echo "error: missing command: $1"
exit 1
fi
}
check_command tiffcp
check_command identify
mkdir -p "$tmp"
mkdir -p "$bak"
num_done=0
for f in "$src"/*.$scan_format; do
base=$(basename "$f")
f_tmp="$tmp/$base"
f_bak="$bak/$base"
# Count number of images (IFDs) in TIFF
count=$(identify "$f" | wc -l)
if [ "$count" -gt 1 ]; then
echo "fixing $f"
# quasi-lossless in quality, but maybe different compression
false &&
magick "$f[0]" \
-strip \
-compress JPEG \
-quality 95 \
"$f_tmp"
# lossless in quality, but maybe different compression
false &&
magick "$f[0]" -strip -compress LZW "$f_tmp"
# lossless
tiffcp -1 "$f" "$f_tmp"
# atomic backup and replace
cp --link "$f" "$f_bak"
mv "$f_tmp" "$f"
num_done=$((num_done + 1))
# else
# echo "keeping $f"
fi
done
rmdir "$tmp"
if [ $num_done = 0 ]; then
rmdir "$bak" 2>/dev/null
fi
echo "done. fixed $num_done images"