How to add few pictures into one

K.S.Sreeram sreeram at tachyontech.net
Tue Jun 6 13:34:21 CEST 2006


Lad wrote:
> I really would like to have ALL pictures in one file.

import Image

def merge_images( input_files, output_file ) :
    img_list = [Image.open(f) for f in input_files]
    out_width = max( [img.size[0] for img in img_list] )
    out_height = sum( [img.size[1] for img in img_list] )
    out = Image.new( 'RGB', (out_width,out_height) )
    y = 0
    for img in img_list :
        w,h = img.size
        out.paste( img, (0,y,w,y+h) )
        y += h
    out.save( output_file )

Use like this:
>>> merge_images( ['1.jpg','2.jpg','3.jpg'], 'output.jpg' )

Regards
Sreeram

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20060606/cfba392a/attachment.sig>


More information about the Python-list mailing list