-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomp
More file actions
executable file
·88 lines (70 loc) · 2.94 KB
/
comp
File metadata and controls
executable file
·88 lines (70 loc) · 2.94 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
: '
Compares two directories of images.
If the directories contain differently named files, the comparison terminates.
Otherwise, we use ImageMagick to compare the content of pairs of images by name.
If a pair of images are not identical, we generate an animated gif "flicker" diagram to assist in visually
highlighting the differences.
'
ME=$(basename "$0") && readonly ME
# shellcheck disable=SC2164
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
readonly SCRIPT_PATH
source "${SCRIPT_PATH}"/common
if [[ $# -ne 4 ]]; then
logError "${ME}" "Usage DIR1 DIR2 FORMAT OUT_DIR."; exit 1
fi
ERRORS=0
DIR1="${1}" && readonly DIR1
# Ensure that the input directories exit
if [ ! -d "${DIR1}" ]; then
ERRORS=1 && logError "First image directory not accessible at $(sQuote "$(red "${DIR1}")")"
fi
DIR2="${2}" && readonly DIR2
if [ ! -d "${DIR2}" ]; then
ERRORS=1 && logError "${ME}" "Second image directory not accessible at $(sQuote "$(red "${DIR2}")")"
fi
FORMAT="${3}" && readonly FORMAT
if [ "${DIR1}" == "${DIR2}" ]; then
ERRORS=1 && logError "${ME}" "Both arguments point to the same directory $(sQuote "$(red "${DIR1}")")"
fi
# Ensure that Image Magick is installed
identify -version &>/dev/null \
|| { ERRORS=1 && logError "${ME}" "ImageMagick $(sQuote "$(blue "identify")") not found on the system."; }
# Create the output directory if there's no errors up to this point
OUT_DIR="${4}"
readonly OUT_DIR
if [ "$ERRORS" -eq "0" ]; then
if [ ! -d "${OUT_DIR}" ]; then
logInfo "${ME}" "Creating output directory $(sQuote "$(green "${OUT_DIR}")")"
if ! mkdir -p "${OUT_DIR}"; then
ERRORS=1 && logError "${ME}" "Could not create output directory."
fi
fi
fi
# If there's any error, exit
if [ "$ERRORS" -ne "0" ]; then
logError "${ME}" "Exiting due to previous errors."; exit 1
fi
FILESET_1=$(find "${DIR1}" -iname "*.${FORMAT}" -exec basename {} \; | sort);
readonly FILESET_1
FILESET_2=$(find "${DIR2}" -iname "*.${FORMAT}" -exec basename {} \; | sort);
readonly FILESET_2
logInfo "${ME}" "Comparing filesets by name only."
if ! comm -3 <(echo "${FILESET_1[@]}") <(echo "${FILESET_2[@]}"); then
logError "${ME}" "Directories contain differently named files, exiting." && exit 1
else
logInfo "${ME}" "Both filesets contain identically named files."
fi
logInfo "${ME}" "Comparing images by ImageMagick signature."
for BASENAME in ${FILESET_1}; do
FIRST_FILE="${DIR1}/${BASENAME}"
SECOND_FILE="${DIR2}/${BASENAME}"
FIRST_SIGNATURE=$(identify -quiet -format "%#" "${FIRST_FILE}")
SECOND_SIGNATURE=$(identify -quiet -format "%#" "${SECOND_FILE}")
if [ "${FIRST_SIGNATURE}" != "${SECOND_SIGNATURE}" ]; then
FLICKER_FILE="${OUT_DIR}/flicker_${BASENAME%.*}.gif"
logInfo "${ME}" "Differences in $(sQuote "$(blue "${BASENAME}")"), generating flicker animation as $(sQuote "$(blue "${FLICKER_FILE}")")"
"${SCRIPT_PATH}"/flicker "${FIRST_FILE}" "${SECOND_FILE}" "${FLICKER_FILE}"
fi
done