Skip to content

Instantly share code, notes, and snippets.

@nagyv
Last active September 20, 2016 13:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nagyv/a5450c99e2c362b44e32ba6f25d6c1e0 to your computer and use it in GitHub Desktop.
Save nagyv/a5450c99e2c362b44e32ba6f25d6c1e0 to your computer and use it in GitHub Desktop.
Git image diff

What it this for?

Have you ever wandered how to follow changes in images using git? This is a solution for the problem.

How to install

  1. Copy git-imgdiff.sh somewhere under your $PATH. Probably $HOME/bin.
  2. Create the $HOME/.gitattributes file with the following content ~/.gitattributes *.gif diff=image *.jpg diff=image *.png diff=image
  3. Configure git to use the above file by running git config --global core.attributesfile '~/.gitattributes'
  4. Configure git to use the script for image types by running git config --global diff.image.command '~/bin/git-imgdiff.sh'

References

My script was created by merging other people's approach. It handles nicely missing images as well.

#!/bin/sh
name="$1"
f1="$2"
f2="$5"
echo "Diffing image $name"
if ! [ -f "$f1" ]
then
convert "$f2" -background Orange label:"New image" +swap -gravity Center -append png:- | display -title "$name" -
echo "New image found: $name"
exit 0
fi
if ! [ -f "$f2" ]
then
convert "$f1" -background Orange label:"Image removed" +swap -gravity Center -append png:- | display -title "$name" -
echo "Image $name has been removed"
exit 0
fi
compare -quiet "$f1" "$f2" png:- | display -title "$name" -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment