LoginSignup
9
11

More than 5 years have passed since last update.

git diffで画像の差分をみる

Posted at

Image diffs with git で紹介されていたネタです。

最近UIまわりをいじっているので画像をいろいろ githubにいれたりすることがあります。githubの画像差分機能はそれなりに優秀なのですが、そもそも commitするまえに確認したいことがあります。でもそのままでは gifは画像の差分を見せてくれません。

でも gitの configurabilityがあればなんとかなります。

まず、システム全体で imageファイルを見割られるように、globalな attributeファイルを指定します。

git config --global core.attributesfile '~/.gitattributes'

~/.gitattributeの中身は以下の様なのものです。万が一、すでに globalな attributeファイルが有ったりしたら適宜編集してください。

*.gif diff=image
*.jpg diff=image
*.png diff=image

gitになにが画像ファイルか教えこんだところで、これらの画像ファイルの比較の仕方を指定します。

git config --global diff.image.command '~/bin/git-imgdiff'

問題の ~/bin/git-imgdiff は、以下のようにしました。自分は OS-Xなので、もと記事とチョット違います。

#!/bin/sh
compare $2 $1 png:- | montage -geometry +4+4 $2 png:- $1 /tmp/diff.png
open /tmp/diff.png

これで以下のような差分を表示できます。

image

9
11
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
11