2007-05-18

Pshop Image Limited

I have this one task at "work" that I did using Photoshop. It's simple and requires the same few steps to be performed each time I do it. I may do it a few times a week at most, but each time I did I wished I wasn't doing it by hand. I thought "I know! I'll learn Photoshop scripting. It's just javascript..."

But I put it off since I was already busy not learning Django...

Then the other day I realized I could just do it in Python using the Python Imaging Library. A few minutes later and it was done.



#!/usr/local/bin/python

from PIL import Image
import sys

src = sys.argv[1]
dst = 'output.jpg'
orig = Image.open(src)
thumb = orig.resize((450,321))
new = Image.new('RGB', (1500,1500))
for j in range(5):
for i in range(5):
new.paste(thumb, (j*450,i*321))
new.save(dst)


Thanks to my friend, the Python Challenge, for making me spend so much time with dear old PIL back in the day.