tiling ID photos in python

Yet an other code snippet of Python Imaging Library (PIL):

#! /usr/bin/python
import Image, ImageFile
im = Image.open("DSC01264.png")
height = 1181
width = 1772
ni = width / im.size[0]
nj = height / im.size[1]

out = Image.new("RGB", (width, height), "white")
imarging = ((width / ni) - im.size[0]) / 2
jmarging = ((height / nj) - im.size[1]) / 2

for i in xrange(ni):
    for j in xrange(nj):
        ix = imarging + i * (im.size[0] + 2 * imarging)
        jx = jmarging + j * (im.size[1] + 2 * jmarging)
        out.paste(im, (ix, jx))

#http://mail.python.org/pipermail/image-sig/1999-August/000816.html
ImageFile.MAXBLOCK = 1000000
out.save("tiles.jpg", "JPEG", quality=90, optimize=True)