Skip to content

Instantly share code, notes, and snippets.

@nagyv
Last active Sep 20, 2016
Embed
What would you like to do?
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