Add background color flag to diff-image

This commit is contained in:
Sam Miller
2019-01-29 11:33:50 -08:00
parent b537ff981b
commit a01cbe6b9f

View File

@ -9,6 +9,7 @@ usage()
echo echo
echo "Options:" echo "Options:"
echo " -h Print this help." echo " -h Print this help."
echo " -b <color> Use this as the background color; defaults to white."
echo " -c <color> Highlight differences with this color; defaults to red." echo " -c <color> Highlight differences with this color; defaults to red."
echo " -e Show Exif differences only; don't compare the image data." echo " -e Show Exif differences only; don't compare the image data."
echo " -f <fuzz> Use the specified percentage of fuzz. Defaults to " echo " -f <fuzz> Use the specified percentage of fuzz. Defaults to "
@ -19,18 +20,22 @@ usage()
} }
backgroundcolor=
color= color=
exif_only=false exif_only=false
fuzz= fuzz=
name1= name1=
name2= name2=
while getopts "hc:ef:n:N:" opt while getopts "hb:c:ef:n:N:" opt
do do
case "$opt" in case "$opt" in
h) h)
usage usage
exit 0 exit 0
;; ;;
b)
backgroundcolor="$OPTARG"
;;
c) c)
color="$OPTARG" color="$OPTARG"
;; ;;
@ -156,6 +161,12 @@ then
fuzz='5' fuzz='5'
fi fi
backgroundcolor_flag=
if [ -n "$backgroundcolor" ]
then
backgroundcolor_flag="-background $backgroundcolor"
fi
color_flag= color_flag=
if [ -n "$color" ] if [ -n "$color" ]
then then
@ -168,8 +179,8 @@ then
fuzz_flag="-fuzz $fuzz%" fuzz_flag="-fuzz $fuzz%"
fi fi
compare $color_flag $fuzz_flag "$f1" "$f2" png:- | \ compare $color_flag $fuzz_flag $backgroundcolor_flag "$f1" "$f2" png:- | \
montage -geometry +4+4 "$f1" - "$f2" png:- >"$destfile" 2>/dev/null || true montage -geometry +4+4 $backgroundcolor_flag "$f1" - "$f2" png:- >"$destfile" 2>/dev/null || true
if which xdg-open > /dev/null if which xdg-open > /dev/null
then then
xdg-open "$destfile" xdg-open "$destfile"