-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep6_convertPPMtoPNG.sh
73 lines (59 loc) · 2.02 KB
/
step6_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
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
#!/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 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 -strip all "${png}"
fi
# Check if the PPM needs removing ...
if [[ -f ${png} ]]; then
echo "Removing \"${ppm}\" ..."
# Remove PPM ...
rm "${ppm}"
fi
done
# Loop over PPM images ...
for ppm in output/*.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}\" ..."
# Extract sea level from file name and make title ...
str="${ppm%.ppm}"
str="${str#output/}"
str="${str:0:1},${str:1:5} sea level rise"
# Make PNG ...
convert "${ppm}" -gravity north -stroke none -fill white -font Courier -pointsize 72 -annotate 0 "${str}" "${png}"
optipng -strip all "${png}"
fi
# Check if the PPM needs removing ...
if [[ -f ${png} ]]; then
echo "Removing \"${ppm}\" ..."
# Remove PPM ...
rm "${ppm}"
fi
done