#!/usr/bin/python26
import ImageChops
from PIL import Image
import urllib2, urllib
from StringIO import StringIO
import sys, os
def equal(im1, im2):
return ImageChops.difference(im1, im2).getbbox() is None
im = "http://www.poltz.com/blognews/this-is-only-a-test.jpg"
#im = "http://www.mediabistro.com/unbeige/files/original/fill%20in%20the%20bubble.jpg"
outfile = "/foo/bar/test.jpg"
try:
remote = urllib2.urlopen(im)
im1 = Image.open(StringIO(remote.read()))
except Exception, e:
print 'Unable to fetch image %s: %s' % (im, e)
if os.path.isfile(outfile):
im2 = Image.open(outfile)
if (equal(im1, im2)):
print "no new img"
else:
print "new img"
os.remove(outfile)
im1.save(outfile,quality=100)
else:
print "%s was a new pic" % (outfile)
im1.save(outfile,quality=100)