-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convertPPMtoPNG.sh
47 lines (40 loc) · 1.33 KB
/
convertPPMtoPNG.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
#!/usr/bin/env bash
# Check that non-standard programs are installed. "standard" programs are
# anything that is specified in the POSIX.1-2008 standard (and the IEEE Std
# 1003.1 standard) or that is a BASH builtin command. Therefore, "non-standard"
# programs are anything that does not appear on the following two lists:
# * https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html
# * https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html
if ! type convert &> /dev/null; then
echo "ERROR: \"convert\" is not installed." >&2
exit 1
fi
if ! type exiftool &> /dev/null; then
echo "ERROR: \"exiftool\" is not installed." >&2
exit 1
fi
if ! type optipng &> /dev/null; then
echo "ERROR: \"optipng\" is not installed." >&2
exit 1
fi
# Loop over PPM images ...
for ppm in *.ppm; do
# Skip those that do not exist ...
[[ ! -f $ppm ]] && continue
# Deduce PNG image ...
png="${ppm%.ppm}.png"
# Check if the PNG needs making ...
if [[ $ppm -nt $png ]]; then
echo "Making \"$png\" ..."
# Make PNG ...
convert "$ppm" "$png"
optipng "$png"
exiftool -overwrite_original -all= "$png"
fi
# Check if the PPM needs removing ...
if [[ -f $png ]]; then
echo "Removing \"$ppm\" ..."
# Remove PPM ...
rm "$ppm"
fi
done