Do you want to put a black/white/both frame around your picture?

by

I was tired of looking at complicated (ehm, not free) applications to do this, so I wrote my own 🙂

Enjoy


#!/usr/bin/env python

from PIL import Image
import sys

if len(sys.argv)!=3 and len(sys.argv)!=4:
    print "USAGE: <command> <filename> <black border percentage> <white border percentage>"
    sys.exit(0)
    
filename=sys.argv[1]
percBlack=float(sys.argv[2])

if len(sys.argv)==3:
    percWhite=0
else:
    percWhite=float(sys.argv[3])
    

im = Image.open(filename)
blackWidth=int(im.size[0]*percBlack)
whiteWidth=int(im.size[0]*percWhite)
white = Image.new('RGB',(im.size[0]+whiteWidth,im.size[1]+whiteWidth),'white')
black = Image.new('RGB',(white.size[0]+blackWidth,white.size[1]+blackWidth),'black')
white.paste(im,(int(whiteWidth/2),int(whiteWidth/2)))
black.paste(white,(int(blackWidth/2),int(blackWidth/2)))
black.save('framed-'+filename)

Advertisements

One Response to “Do you want to put a black/white/both frame around your picture?”

  1. vincent Says:

    Great snippet!! Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: