Home > Uncategorized > tiling ID photos in python

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)
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

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: