Skip to content

Instantly share code, notes, and snippets.

@rroblak
Last active October 26, 2023 03:22
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save rroblak/da71c748cf4be5a5a11b to your computer and use it in GitHub Desktop.
Save rroblak/da71c748cf4be5a5a11b to your computer and use it in GitHub Desktop.
git diff image files on the command line, with color

This is a simple way to spot check that the modified image in your git index is the image you actually want without having to leave the command line.

Example: http://i.imgur.com/RUenUcM.png

Instructions

  1. Install git, ImageMagick, and jp2a via your favorite package manager.
  2. Put img-ascii-diff somewhere (e.g. ~/bin/img-ascii-diff).
  3. Put attributes in ~/.config/git/attributes.
  4. Modify ~/.gitconfig and add the lines below, pointing to wherever you put img-ascii-diff.
  5. ???
  6. Profit!

@rroblak and @tylercal

*.jpg diff=asciidiff
*.jpeg diff=asciidiff
*.png diff=asciidiff
*.gif diff=asciidiff
[diff "asciidiff"]
textconv = ~/bin/img-ascii-diff
#!/bin/bash
# We have to convert to jpeg before we identify, otherwise
# identify returns 0x0 for the committed version of the file
# (no idea why this is the case). Also, we wrap the identify
# command in an echo to append a newline.
convert -quiet $1 jpg:- | echo $(identify -format '%[fx:w]x%[fx:h]' -)
convert -quiet $1 jpg:- | jp2a --colors --width=60 -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment