Skip to content

Instantly share code, notes, and snippets.

Created August 15, 2012 05:52
What would you like to do?
Quick, simple implementation of Error Level Analysis
#!/usr/bin/env python
# This is a really simple implementation of ELA as described in
# You shouldn't actually use it, or at least read the paper carefully
# and implement more of the techniques before drawing any conclusions.
from PIL import Image, ImageChops, ImageEnhance
import sys, os.path
filename = sys.argv[1]
resaved = filename + '.resaved.jpg'
ela = filename + '.ela.png'
im =, 'JPEG', quality=95)
resaved_im =
ela_im = ImageChops.difference(im, resaved_im)
extrema = ela_im.getextrema()
max_diff = max([ex[1] for ex in extrema])
scale = 255.0/max_diff
ela_im = ImageEnhance.Brightness(ela_im).enhance(scale)
print "Maximum difference was %d" % (max_diff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment