Skip to content

Instantly share code, notes, and snippets.

@riklomas
Created May 19, 2009 20:42
Show Gist options
  • Save riklomas/114387 to your computer and use it in GitHub Desktop.
Save riklomas/114387 to your computer and use it in GitHub Desktop.
import Image
def borders(filename):
im = Image.open(filename)
im = im.convert("RGB")
pix = im.load()
x = im.size[0]-1
y = im.size[1]-1
matches = True
for i in xrange(x):
if pix[i, 0] != pix[i+1, 0] or pix[i, y] != pix[i+1, y]:
matches = False
break
if matches:
for i in xrange(y):
if pix[0, i] != pix[0, i+1] or pix[x, i] != pix[x, i+1]:
matches = False
break
if matches:
return '#%02x%02x%02x' % pix[0, 0]
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment