Skip to content

Instantly share code, notes, and snippets.

@NiGhTTraX
Created January 30, 2017 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NiGhTTraX/49bd7f664e139c82039e79cc14f14e0d to your computer and use it in GitHub Desktop.
Save NiGhTTraX/49bd7f664e139c82039e79cc14f14e0d to your computer and use it in GitHub Desktop.
Diffing images with git
#!/bin/bash
DIFF_PATH=/tmp/diff.png
MONTAGE_PATH=/tmp/montage.png
rm -rf $DIFF_PATH $MONTAGE_PATH
# Try to diff the images and create a montage with the original on
# the left, diff in the middle and the new one on the right.
DIFF=$(compare $2 $1 png:- > $DIFF_PATH)
# XXX: for some reason IG exits with 1 when it successfully creates the diff
if [[ $? == 1 ]]; then
montage -label Original $2 -label Diff $DIFF_PATH -label New $1 \
-tile x1 -geometry '433x+4+4>' $MONTAGE_PATH
else
# If the images have different sizes the diff will fail.
# In this case, create a montage with just the original and the new one.
montage -label Original $2 -label New $1 \
-tile x1 -geometry '650x+4+4>' $MONTAGE_PATH
fi
if [[ $? == 0 ]]; then
display $MONTAGE_PATH> /dev/null 2>&1
fi
git config --global core.attributesfile '~/.gitattributes'
echo '*.png diff=image' > ~/.gitattributes
git config --global diff.image.command '~/git-imgdiff.sh'
apt-get install imagemagick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment