Skip to content

Instantly share code, notes, and snippets.

@backus
Created June 4, 2017 00:00
Show Gist options
  • Save backus/1eee2adfdb0c96692b556cfc1611e5ea to your computer and use it in GitHub Desktop.
Save backus/1eee2adfdb0c96692b556cfc1611e5ea to your computer and use it in GitHub Desktop.
Simple image diffing with phantomjs and imagemagick
var system = require('system');
var page = require('webpage').create();
page.viewportSize = {
width: 1024,
height: 768
};
page.open(system.args[1], function() {
page.render(system.args[2]);
phantom.exit();
});
#!/bin/bash
url=$1
image=$2
new_image="$TMPDIR$image"
diff_image="$TMPDIR""diff-$image"
diff_overlay_image="$TMPDIR""diff-overlay-$image"
phantomjs snapshot.js "$url" "$new_image"
if image-diff "$image" "$new_image" "$diff_image"; then
echo "Screenshots match for $url"
exit 0
fi
composite -compose atop "$diff_image" "$image" "$diff_overlay_image"
echo "Difference found"
open "$diff_overlay_image"
  1. npm install -g image-diff
  2. Generate a screenshot which you like. phantomjs snapshot.js http://example.com/page page.png
  3. Diff! ./snapshot.sh http://example.com/page page.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment