url-diff: commpact the settings definitions
This commit is contained in:
parent
4230262f64
commit
2fa00047cc
1 changed files with 30 additions and 15 deletions
45
url-diff.sh
45
url-diff.sh
|
@ -6,16 +6,21 @@ if [[ ! -z "${URLDIFF_STORAGE_DIR}" ]]; then loc_storage="${URLDIFF_STORAGE_DIR}
|
||||||
loc_firefox_profile="${loc_storage}/firefox-profile";
|
loc_firefox_profile="${loc_storage}/firefox-profile";
|
||||||
loc_prev_images="${loc_storage}/previous-images";
|
loc_prev_images="${loc_storage}/previous-images";
|
||||||
|
|
||||||
highlight_colour="#ff000044";
|
highlight_colour="${URLDIFF_HIGHLIGHT_COLOUR:-#ff000044}";
|
||||||
if [[ ! -z "${URLDIFF_HIGHLIGHT_COLOUR}" ]]; then highlight_colour="${URLDIFF_HIGHLIGHT_COLOUR}"; fi
|
|
||||||
|
|
||||||
quiet="false";
|
quiet="${URLDIFF_QUIET:-false}";
|
||||||
if [[ ! -z "${URLDIFF_QUIET}" ]]; then quiet="${URLDIFF_QUIET}"; fi
|
|
||||||
|
|
||||||
window_width="${URLDIFF_WINDOW_WIDTH}";
|
window_width="${URLDIFF_WINDOW_WIDTH}";
|
||||||
|
|
||||||
change_threshold="2";
|
change_threshold="${URLDIFF_CHANGE_THRESHOLD:-2}";
|
||||||
if [[ ! -z "${URLDIFF_CHANGE_THRESHOLD}" ]]; then change_threshold="${URLDIFF_CHANGE_THRESHOLD}"; fi
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
if [[ -z "$(type -p calc)" ]]; then
|
||||||
|
echo "calc command not detected - it would appear it is not installed" >&2;
|
||||||
|
echo "Install it like this on debian systems:" >&2;
|
||||||
|
echo " sudo apt install apcalc" >&2;
|
||||||
|
fi
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
@ -41,7 +46,9 @@ calculate_percentage_colour() {
|
||||||
image_height="$(identify -format "%[fx:h]" "${loc_image}")";
|
image_height="$(identify -format "%[fx:h]" "${loc_image}")";
|
||||||
pixel_count_colour="$(convert "${loc_image}" -fill black +opaque "${colour}" -fill white -opaque "${colour}" -format "%[fx:w*h*mean]" info:)";
|
pixel_count_colour="$(convert "${loc_image}" -fill black +opaque "${colour}" -fill white -opaque "${colour}" -format "%[fx:w*h*mean]" info:)";
|
||||||
|
|
||||||
echo "(${pixel_count_colour} / (${image_width}*${image_height})) * 100" | bc -l
|
# echo "image_width: ${image_width}, image_height: ${image_height}, pixel_count_colour: ${pixel_count_colour}" >&2;
|
||||||
|
|
||||||
|
calc -p "(${pixel_count_colour} / (${image_width}*${image_height})) * 100" | tr -d '~';
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -58,17 +65,19 @@ Usage:
|
||||||
|
|
||||||
Subcommands:
|
Subcommands:
|
||||||
check {url} {output_diff_image} [{output_apng}]
|
check {url} {output_diff_image} [{output_apng}]
|
||||||
Checks the given URL for differences, and saves a diff image to a
|
Checks the given URL for differences, and saves a diff
|
||||||
specified location. Exits with code 0 if differences are found, or code
|
image to a specified location. Exits with code 0 if
|
||||||
1 if no differences are found.
|
differences are found, or code 1 if no differences are
|
||||||
Optionally generates an animated PNG that alternates between the 2 screenshots.
|
found.
|
||||||
|
Optionally generates an animated PNG that alternates
|
||||||
|
between the 2 screenshots.
|
||||||
|
|
||||||
Environment Variables:
|
Environment Variables:
|
||||||
Variable Default variable
|
Variable Default variable
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
URLDIFF_STORAGE_DIR ~/.config/url-diff
|
URLDIFF_STORAGE_DIR ~/.config/url-diff
|
||||||
The directory in which previous images are stored to diff against.
|
The directory in which previous images are stored to diff
|
||||||
The firefox profile is also stored in here.
|
against. The firefox profile is also stored in here.
|
||||||
|
|
||||||
URLDIFF_HIGHLIGHT_COLOUR #ffffffcc
|
URLDIFF_HIGHLIGHT_COLOUR #ffffffcc
|
||||||
The colour to highlight any changes in.
|
The colour to highlight any changes in.
|
||||||
|
@ -77,7 +86,8 @@ Environment Variables:
|
||||||
The window width to tell firefox to screenshot with.
|
The window width to tell firefox to screenshot with.
|
||||||
|
|
||||||
URLDIFF_CHANGE_THRESHOLD 2
|
URLDIFF_CHANGE_THRESHOLD 2
|
||||||
The percentage of the screenshot that should have changed for it to count.
|
The percentage of the screenshot that should have
|
||||||
|
changed for it to count.
|
||||||
Allows for ignoring random minor rendering artifacts.
|
Allows for ignoring random minor rendering artifacts.
|
||||||
" >&2;
|
" >&2;
|
||||||
fi
|
fi
|
||||||
|
@ -129,10 +139,15 @@ case "${mode}" in
|
||||||
# Work out how much of the image has changed
|
# Work out how much of the image has changed
|
||||||
percentage_changed="$(calculate_percentage_colour "${tmpdir}/transp.png" "${highlight_colour}")";
|
percentage_changed="$(calculate_percentage_colour "${tmpdir}/transp.png" "${highlight_colour}")";
|
||||||
|
|
||||||
|
if [[ -z "${percentage_changed}" ]]; then
|
||||||
|
echo "Something went wrong when calculating the percentage changed - no value was returned";
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
log_msg "Changed: ${percentage_changed}%";
|
log_msg "Changed: ${percentage_changed}%";
|
||||||
|
|
||||||
# if [[ "${img_hash_new}" == "${img_hash_old}" ]]; then
|
# if [[ "${img_hash_new}" == "${img_hash_old}" ]]; then
|
||||||
if [[ "$(echo "${percentage_changed} > ${change_threshold}" | bc -l)" -eq 0 ]]; then
|
if [[ "$(calc -p "${percentage_changed} > ${change_threshold}")" -eq 0 ]]; then
|
||||||
log_msg "No changes detected.";
|
log_msg "No changes detected.";
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue