Richard Jones' Log: Photo border and copyright script

Sun, 07 Mar 2004

Just threw this PIL-using Python script together to automatically resize and add a border with copyright notice to my Photo Friday images:

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
import sys, Image, ImageOps

photo = Image.open(sys.argv[1])
photo.thumbnail((500, 500), Image.ANTIALIAS)
copy = Image.open('/home/richard/Documents/2004 richard@mecanicalcat.net.png')
photo = ImageOps.expand(photo, border=copy.size[1])
photo.paste(copy, (photo.size[0]-copy.size[0], photo.size[1]-copy.size[1]))
photo.save('out.jpg')

Yes, I cheated and used a pre-drawn image for the copyright text. Rendering that is left as an exercise for the reader :)

[Edit: switched to using the thumbnail method, thanks Ian Bicking for the pointer in the comments]

[Edit 2: indicated that I use PIL :)]

Comment by Ian Bicking on Sun, 07 Mar 2004

I think Image objects have a thumbnail method that will decrease the size but keep the aspect ratio, which I think will save a few lines and allow for non-square constraining sizes.

Comment by Richard Jones on Sun, 07 Mar 2004

Ah, I'd completely forgotten about that method.


If you're going to use it, don't forget that unlike some other methods it modifies the image in-place, and returns None.

Comment by David Rostenne on Wed, 24 Mar 2004

You need to fix your copyright image so it says 'mechanical' ... you left out the *h*!!

Cheers,

Dave

Comment by Richard on Wed, 24 Mar 2004

Heh :)