Image concatenation in PIL

skip at pobox.com skip at pobox.com
Wed Aug 9 19:18:59 EDT 2006


Looking through the PIL docs I didn't see any obvious (one-line) way of
concatenating two images.  Given im1 and im2 which I wish to concatenate
left-to-right, is this the simplest I can do?

    def imconcat(im1, im2):
        # concatenate im1 and im2 left-to-right
        h1, w1 = im1.size
        h2, w2 = im2.size
        im3 = PIL.Image.new("RGB", (max(h1, h2), w1+w2))
        im3.paste(im1)
        im3.paste(im2, (0, w1, h2, w2))
        return im3

I was hoping for something almost as simple as the netpbm command

    pnmcat -lr im1 im2

Thx,

Skip



More information about the Python-list mailing list