path:
/genthumbs.sh
811 B | plain
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
#!/bin/sh
set -eu
set -o pipefail
if [ $# -lt 1 ]; then
echo "Usage: $0 in_dir [out_dir]" >&2
exit 1
fi
in_dir="${1}/"
out_dir="${2:-jpgphotos}"
if [ ! -d "${out_dir}" ]; then
mkdir ${out_dir} || exit 1
fi
for i in "${in_dir}/"*; do
ext="${i##*.}"
ext="$(echo ${ext} | tr '[:upper:]' '[:lower:]')"
case ${ext} in
png|jpg|jpeg)
fn="$(basename $i)"
dest="${out_dir}/${fn%.*}.jpg"
# if file exist in destination, make sure it is newer than src
[ -f "${dest}" ] && [ "${dest}" -nt "$i" ] && continue;
if ! magick "$i" -auto-orient -resize x200 -strip "${dest}"; then
printf "%-20s\t=x=> %s\n" "$fn" "$dest"
continue
fi
printf "%-20s\t===> %s\n" "$fn" "$dest"
#exiftool -P -overwrite_original_in_place -Orientation=0 -n "${dest}"
;;
*)
echo "Convertion done"
;;
esac
done