-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheics
More file actions
executable file
·49 lines (45 loc) · 1.15 KB
/
heics
File metadata and controls
executable file
·49 lines (45 loc) · 1.15 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
#!/usr/bin/env zsh
set -euo pipefail
setopt localoptions nocaseglob
extensions=(${(f)"$(globs images -x heic heif)"})
files=()
for ext in "${extensions[@]}"; do
files+=(${~ext}(N))
done
if [[ ${#files[@]} -eq 0 ]]; then
echo "No image files found." >&2
exit 1
fi
orig_size=0
for f in "${files[@]}"; do
orig_size=$(( orig_size + $(stat -f%z "$f") ))
done
mkdir -p original
printf '%s\0' "${files[@]}" | parallel -0 '
heic_file="{.}.heic"
heic {}
if [[ -f "$heic_file" ]]; then
touch -r {} "$heic_file"
fi
mv {} original/
'
heic_size=0
converted=0
for f in "${files[@]}"; do
heic="${f%.*}.heic"
if [[ -f "$heic" ]]; then
heic_size=$(( heic_size + $(stat -f%z "$heic") ))
(( converted++ ))
fi
done
saved=$(( orig_size - heic_size ))
if (( orig_size > 0 )); then
pct=$(( saved * 100 / orig_size ))
if (( orig_size > 1048576 )); then
printf '%d files: %.1fMB → %.1fMB (saved %.1fMB, %d%%)\n' \
$converted $(( orig_size / 1048576.0 )) $(( heic_size / 1048576.0 )) $(( saved / 1048576.0 )) $pct
else
printf '%d files: %dKB → %dKB (saved %dKB, %d%%)\n' \
$converted $(( orig_size / 1024 )) $(( heic_size / 1024 )) $(( saved / 1024 )) $pct
fi
fi