-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave.sh
More file actions
executable file
·33 lines (27 loc) · 730 Bytes
/
Copy pathsave.sh
File metadata and controls
executable file
·33 lines (27 loc) · 730 Bytes
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
#!/bin/bash
#
# Save a PPM image to a timestamped PNG file in the images/ directory.
#
# E.g.
#
# save.sh chapter8 image2.ppm # creates images/chapter8_<timestamp>.png from image2.ppm
#
# save.sh chapter8 # creates images/chapter8_<timestamp>.png from default image.ppm
#
# save.sh # creates images/<timestamp>.png
#
set -o nounset
set -o errexit
TIMESTAMP=$(date "+%Y%m%d_%H%M%S")
PREFIX=${1:-}
SRC_IMAGE=${2:-image.ppm}
DST_DIR=${3:-images}
if [[ -z $PREFIX ]]
then
DEST_IMAGE="${DST_DIR}/${TIMESTAMP}.png"
else
DEST_IMAGE="${DST_DIR}/${PREFIX}_${TIMESTAMP}.png"
fi
mkdir -p $(dirname "$DEST_IMAGE")
convert "$SRC_IMAGE" "$DEST_IMAGE"
echo "$SRC_IMAGE -> $DEST_IMAGE"