From 670ec172d6844b34db133075b40bc9b785294e16 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 21 Oct 2018 14:25:58 +0100 Subject: [PATCH] Add Linux support --- README.md | 16 ++++++++++++---- diff-image | 37 +++++++++++++++++++++---------------- git_diff_image | 6 +++--- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index c818cdd..2782ade 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ It can also be run as a direct CLI command for diffing two image files. Platforms --------- -Only macOS at the moment. Patches welcome! +Only macOS and Linux at the moment. Patches welcome! Examples -------- @@ -41,9 +41,17 @@ Installation 1. Install exiftool and ImageMagick. (The script will cope with these missing, but it's not going to be very exciting without them). -```bash -brew install exiftool imagemagick -``` + macOS: + + ```bash + brew install exiftool imagemagick + ``` + + Debian / Ubuntu: + + ```bash + sudo apt install exiftool imagemagick xdg-open + ``` 2. Run `./install.sh`, which will configure your global git config for you. It will tell you what it's done, so it should look something like this: diff --git a/diff-image b/diff-image index faf9716..5876abe 100755 --- a/diff-image +++ b/diff-image @@ -12,7 +12,7 @@ usage() echo " -c Highlight differences with this color; defaults to red." echo " -e Show Exif differences only; don't compare the image data." echo " -f Use the specified percentage of fuzz. Defaults to " - echo " 5% for JPEGs, zero otherwise." + echo " 5% for JPEGs, zero otherwise." echo " -n The name to give the first file." echo " -N The name to give the second file." echo @@ -60,24 +60,24 @@ fi f1="$1" f2="$2" -if [ ! -f "$f1" ] +if [[ "$f1" != '/dev/null' ]] && [[ ! -f "$f1" ]] then echo "$f1: No such file." >&2 exit 1 fi -if [ ! -f "$f2" ] +if [[ "$f2" != '/dev/null' ]] && [[ ! -f "$f2" ]] then echo "$f2: No such file." >&2 usage exit 1 fi -if [ -z "$name1" ] +if [[ -z "$name1" ]] then name1="$f1" fi -if [ -z "$name2" ] +if [[ -z "$name2" ]] then name1="$f2" fi @@ -93,14 +93,14 @@ fi exif() { - if [ "$1" = /dev/null ] + if [[ "$1" = /dev/null ]] then echo /dev/null return fi - local b=$(basename "$1") - local d=$(mktemp -t "$b") + local b="$(basename "$1")" + local d="$(mktemp -t "$b.XXXXXX")" exiftool "$1" | grep -v 'File Name' | \ grep -v 'Directory' | \ @@ -121,10 +121,10 @@ diff_clean_names() } -if which -s exiftool +if which exiftool > /dev/null then - d1=$(exif "$f1") - d2=$(exif "$f2") + d1="$(exif "$f1")" + d2="$(exif "$f2")" diff_clean_names "$d1" "$d2" else diff_clean_names "$f1" "$f2" @@ -136,8 +136,8 @@ then fi if \ - ! which -s compare || \ - ! which -s montage + ! which compare > /dev/null || \ + ! which montage > /dev/null then echo 'ImageMagick is not installed.' >&2 exit 1 @@ -148,8 +148,8 @@ then exit 0 fi -bn=$(basename "$f1") -destfile=$(mktemp -t "$bn").png +bn="$(basename "$f1")" +destfile="$(mktemp -t "$bn.XXXXXX").png" if [ -z "$fuzz" ] && ( [ "$ext" = "jpeg" ] || [ "$ext" = "jpg" ] ) then @@ -170,4 +170,9 @@ fi compare $color_flag $fuzz_flag "$f1" "$f2" png:- | \ montage -geometry +4+4 "$f1" - "$f2" png:- >"$destfile" 2>/dev/null || true -open "$destfile" +if which xdg-open > /dev/null +then + xdg-open "$destfile" +else + open "$destfile" +fi diff --git a/git_diff_image b/git_diff_image index 959b296..d148ed8 100755 --- a/git_diff_image +++ b/git_diff_image @@ -53,12 +53,12 @@ readlink_f() fi } -thisdir=$(dirname $(readlink_f "$0")) +thisdir="$(dirname $(readlink_f "$0"))" e_flag='' if [ -z "${GIT_DIFF_IMAGE_ENABLED-}" ] || \ - ! which -s compare || \ - ! which -s montage + ! which compare > /dev/null || \ + ! which montage > /dev/null then e_flag='-e' fi