How to add few pictures into one

Lad python at hope.cz
Wed Jun 7 10:42:49 EDT 2006


K.S.Sreeram wrote:
> 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,
Thanks a lot
>
>
> --------------enig1BF4CF77824C603826EE139D
> Content-Type: application/pgp-signature
> Content-Transfer-Encoding: base64
> Content-Disposition: inline;
> 	filename="signature.asc"
> Content-Description: OpenPGP digital signature
> X-Google-AttachSize: 253




More information about the Python-list mailing list