Skip to content

Instantly share code, notes, and snippets.

@buhii
Created January 14, 2013 20:05
Show Gist options
  • Save buhii/4532895 to your computer and use it in GitHub Desktop.
Save buhii/4532895 to your computer and use it in GitHub Desktop.
framed.py - draw a frame for any pictures
#!/Users/buhii/.virtualenvs/gemini/bin/python
# -*- coding: utf-8 -*-
import sys
if len(sys.argv) != 2:
print "Usage: framed.py [image path]"
sys.exit(0)
else:
import os
import Image, ImageDraw
GRAY = (100, 100, 100)
imagepath = sys.argv[1]
im = Image.open(imagepath)
draw = ImageDraw.Draw(im)
# draw picture frame
size = (im.size[0] - 1, im.size[1] - 1)
draw.line(( 0, 0, 0, size[1]), fill=GRAY)
draw.line(( 0, size[1], size[0], size[1]), fill=GRAY)
draw.line((size[0], size[1], size[0], 0), fill=GRAY)
draw.line((size[0], 0, 0, 0), fill=GRAY)
del draw
filename_fragment, ext = os.path.splitext(imagepath)
im.save(filename_fragment + '_framed' + ext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment